Dealing With I/O is Blocking Ui
up vote
-1
down vote
favorite
i'm trying to Make an small Encryptor with Winforms
The Encryption function doesn't need to interact with the UI but the Progress function does.
Here is My Encryption Method
public static void Enc(string Target)
{
if (IsFileEncrypted(Target)) { }
else
{
string n = Target;
try
{
var aes = new AesManaged();
aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
aes.KeySize = aes.LegalKeySizes[0].MaxSize;
var salt = GetBytes(SaltKey);
var key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
aes.Key = key.GetBytes(aes.KeySize / 8);
aes.IV = key.GetBytes(aes.BlockSize / 8);
aes.Mode = CipherMode.CBC;
ICryptoTransform transform = aes.CreateEncryptor(aes.Key, aes.IV);
using (var dest = new FileStream(CCX(Target), FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
using (var cryptoStream = new CryptoStream(dest, transform, CryptoStreamMode.Write))
{
using (var source = new FileStream(Target, FileMode.Open, FileAccess.Read, FileShare.Read))
{
source.CopyTo(cryptoStream);
}
}
}
}
catch (Exception m) { MessageBox.Show(m.Message); }
File.Delete(n);
}
}
and here is My Button Click event
private void EncMulti_Click(object sender, EventArgs e)
{
List<string> chooseditems = new List<string>();
OpenFileDialog op = new OpenFileDialog();
op.Multiselect = true;
if(op.ShowDialog() == DialogResult.OK)
{
foreach (var item in op.FileNames)
{
chooseditems.Add(item);
}
ProgressMulti.Maximum = chooseditems.Count;
}
else { }
for (int i = 0; i < chooseditems.Count; i++)
{
if (!SecurityCore.Encryptor.IsFileEncrypted(chooseditems[i]))
{
SecurityCore.Encryptor.ENC(chooseditems[i]);
ProgressMulti.Value++;
}
else { ProgressMulti.Value++; }
}
}
i can't deal with this , i've tried Background workers With Invoke Method to
update Progress Bar Value but it's the same problem
c#
add a comment |
up vote
-1
down vote
favorite
i'm trying to Make an small Encryptor with Winforms
The Encryption function doesn't need to interact with the UI but the Progress function does.
Here is My Encryption Method
public static void Enc(string Target)
{
if (IsFileEncrypted(Target)) { }
else
{
string n = Target;
try
{
var aes = new AesManaged();
aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
aes.KeySize = aes.LegalKeySizes[0].MaxSize;
var salt = GetBytes(SaltKey);
var key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
aes.Key = key.GetBytes(aes.KeySize / 8);
aes.IV = key.GetBytes(aes.BlockSize / 8);
aes.Mode = CipherMode.CBC;
ICryptoTransform transform = aes.CreateEncryptor(aes.Key, aes.IV);
using (var dest = new FileStream(CCX(Target), FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
using (var cryptoStream = new CryptoStream(dest, transform, CryptoStreamMode.Write))
{
using (var source = new FileStream(Target, FileMode.Open, FileAccess.Read, FileShare.Read))
{
source.CopyTo(cryptoStream);
}
}
}
}
catch (Exception m) { MessageBox.Show(m.Message); }
File.Delete(n);
}
}
and here is My Button Click event
private void EncMulti_Click(object sender, EventArgs e)
{
List<string> chooseditems = new List<string>();
OpenFileDialog op = new OpenFileDialog();
op.Multiselect = true;
if(op.ShowDialog() == DialogResult.OK)
{
foreach (var item in op.FileNames)
{
chooseditems.Add(item);
}
ProgressMulti.Maximum = chooseditems.Count;
}
else { }
for (int i = 0; i < chooseditems.Count; i++)
{
if (!SecurityCore.Encryptor.IsFileEncrypted(chooseditems[i]))
{
SecurityCore.Encryptor.ENC(chooseditems[i]);
ProgressMulti.Value++;
}
else { ProgressMulti.Value++; }
}
}
i can't deal with this , i've tried Background workers With Invoke Method to
update Progress Bar Value but it's the same problem
c#
You posted the code that definitely does not do what you want. If you need help with the BackgroundWorker class then you need to show it.
– Hans Passant
Nov 11 at 15:30
i've tried Bg workers but it's the same , so i removed it
– Muhammed Fares
Nov 11 at 15:33
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
i'm trying to Make an small Encryptor with Winforms
The Encryption function doesn't need to interact with the UI but the Progress function does.
Here is My Encryption Method
public static void Enc(string Target)
{
if (IsFileEncrypted(Target)) { }
else
{
string n = Target;
try
{
var aes = new AesManaged();
aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
aes.KeySize = aes.LegalKeySizes[0].MaxSize;
var salt = GetBytes(SaltKey);
var key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
aes.Key = key.GetBytes(aes.KeySize / 8);
aes.IV = key.GetBytes(aes.BlockSize / 8);
aes.Mode = CipherMode.CBC;
ICryptoTransform transform = aes.CreateEncryptor(aes.Key, aes.IV);
using (var dest = new FileStream(CCX(Target), FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
using (var cryptoStream = new CryptoStream(dest, transform, CryptoStreamMode.Write))
{
using (var source = new FileStream(Target, FileMode.Open, FileAccess.Read, FileShare.Read))
{
source.CopyTo(cryptoStream);
}
}
}
}
catch (Exception m) { MessageBox.Show(m.Message); }
File.Delete(n);
}
}
and here is My Button Click event
private void EncMulti_Click(object sender, EventArgs e)
{
List<string> chooseditems = new List<string>();
OpenFileDialog op = new OpenFileDialog();
op.Multiselect = true;
if(op.ShowDialog() == DialogResult.OK)
{
foreach (var item in op.FileNames)
{
chooseditems.Add(item);
}
ProgressMulti.Maximum = chooseditems.Count;
}
else { }
for (int i = 0; i < chooseditems.Count; i++)
{
if (!SecurityCore.Encryptor.IsFileEncrypted(chooseditems[i]))
{
SecurityCore.Encryptor.ENC(chooseditems[i]);
ProgressMulti.Value++;
}
else { ProgressMulti.Value++; }
}
}
i can't deal with this , i've tried Background workers With Invoke Method to
update Progress Bar Value but it's the same problem
c#
i'm trying to Make an small Encryptor with Winforms
The Encryption function doesn't need to interact with the UI but the Progress function does.
Here is My Encryption Method
public static void Enc(string Target)
{
if (IsFileEncrypted(Target)) { }
else
{
string n = Target;
try
{
var aes = new AesManaged();
aes.BlockSize = aes.LegalBlockSizes[0].MaxSize;
aes.KeySize = aes.LegalKeySizes[0].MaxSize;
var salt = GetBytes(SaltKey);
var key = new Rfc2898DeriveBytes(SKey, salt, Iterations);
aes.Key = key.GetBytes(aes.KeySize / 8);
aes.IV = key.GetBytes(aes.BlockSize / 8);
aes.Mode = CipherMode.CBC;
ICryptoTransform transform = aes.CreateEncryptor(aes.Key, aes.IV);
using (var dest = new FileStream(CCX(Target), FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
using (var cryptoStream = new CryptoStream(dest, transform, CryptoStreamMode.Write))
{
using (var source = new FileStream(Target, FileMode.Open, FileAccess.Read, FileShare.Read))
{
source.CopyTo(cryptoStream);
}
}
}
}
catch (Exception m) { MessageBox.Show(m.Message); }
File.Delete(n);
}
}
and here is My Button Click event
private void EncMulti_Click(object sender, EventArgs e)
{
List<string> chooseditems = new List<string>();
OpenFileDialog op = new OpenFileDialog();
op.Multiselect = true;
if(op.ShowDialog() == DialogResult.OK)
{
foreach (var item in op.FileNames)
{
chooseditems.Add(item);
}
ProgressMulti.Maximum = chooseditems.Count;
}
else { }
for (int i = 0; i < chooseditems.Count; i++)
{
if (!SecurityCore.Encryptor.IsFileEncrypted(chooseditems[i]))
{
SecurityCore.Encryptor.ENC(chooseditems[i]);
ProgressMulti.Value++;
}
else { ProgressMulti.Value++; }
}
}
i can't deal with this , i've tried Background workers With Invoke Method to
update Progress Bar Value but it's the same problem
c#
c#
asked Nov 11 at 15:11
Muhammed Fares
14
14
You posted the code that definitely does not do what you want. If you need help with the BackgroundWorker class then you need to show it.
– Hans Passant
Nov 11 at 15:30
i've tried Bg workers but it's the same , so i removed it
– Muhammed Fares
Nov 11 at 15:33
add a comment |
You posted the code that definitely does not do what you want. If you need help with the BackgroundWorker class then you need to show it.
– Hans Passant
Nov 11 at 15:30
i've tried Bg workers but it's the same , so i removed it
– Muhammed Fares
Nov 11 at 15:33
You posted the code that definitely does not do what you want. If you need help with the BackgroundWorker class then you need to show it.
– Hans Passant
Nov 11 at 15:30
You posted the code that definitely does not do what you want. If you need help with the BackgroundWorker class then you need to show it.
– Hans Passant
Nov 11 at 15:30
i've tried Bg workers but it's the same , so i removed it
– Muhammed Fares
Nov 11 at 15:33
i've tried Bg workers but it's the same , so i removed it
– Muhammed Fares
Nov 11 at 15:33
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53250082%2fdealing-with-i-o-is-blocking-ui%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You posted the code that definitely does not do what you want. If you need help with the BackgroundWorker class then you need to show it.
– Hans Passant
Nov 11 at 15:30
i've tried Bg workers but it's the same , so i removed it
– Muhammed Fares
Nov 11 at 15:33