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










share|improve this question






















  • 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















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










share|improve this question






















  • 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













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










share|improve this question













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#






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Full-time equivalent

Bicuculline

さくらももこ