code_junkie

How can I fix this issue involving BackgroundWorkers in C#

Nov 14th, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.21 KB | None | 0 0
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. if (radioButton1.Checked)
  4. {
  5. backgroundWorker1.RunWorkerAsync();
  6. }
  7.  
  8. if (radioButton2.Checked)
  9. {
  10. StreamReader sr = new StreamReader(Application.StartupPath + @"hakimler.txt");
  11.  
  12. while ((satir = sr.ReadLine()) != null)
  13. {
  14. try
  15. {
  16. bool copy = CopyDirectory(DosyaYolu.kaynak, @"\" + satir + @"" + DosyaYolu.hedef, true);
  17. if (copy)
  18. {
  19. kopya += 1;
  20. }
  21. else
  22. {
  23. sw.WriteLine(satir);
  24. }
  25. }
  26. catch (Exception)
  27. {
  28.  
  29. }
  30. }
  31.  
  32. sw.Close();
  33. MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information);
  34. lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString();
  35. return;
  36. }
  37.  
  38. if (chkPersonel.Checked == true)
  39. {
  40. StreamReader sr = new StreamReader(Application.StartupPath + @"personel.txt");
  41.  
  42. while ((satir = sr.ReadLine()) != null)
  43. {
  44. try
  45. {
  46. bool copy = CopyDirectory(DosyaYolu.kaynak, @"\ab04500-" + satir + @"" + DosyaYolu.hedef, true);
  47. //bool copy = CopyDirectory(Application.StartupPath + @"TELEFON REHBERİ", @"\" + satir + @"c$Documents and SettingsAll UsersStart Menu", true);
  48. if (copy)
  49. {
  50. kopya += 1;
  51. }
  52. else
  53. {
  54. sw.WriteLine(satir);
  55. }
  56. }
  57. catch (Exception)
  58. {
  59.  
  60. }
  61. }
  62.  
  63. sw.Close();
  64.  
  65. MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information);
  66. lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString();
  67. return;
  68. }
  69. else
  70. {
  71. if (txtBilgisayar.Text == "" && txtDongu.Text == "")
  72. {
  73. MessageBox.Show("Boşlukları dolduralım bi zahmet :@", "Bilgisayar Kodlarını girelim lütfen!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  74. return;
  75. }
  76.  
  77. bilgisayar = Convert.ToInt32(txtBilgisayar.Text);
  78. dongu = Convert.ToInt32(txtDongu.Text);
  79.  
  80. for (int i = bilgisayar; i <= dongu; i++)
  81. {
  82. try
  83. {
  84. bool copy = CopyDirectory(DosyaYolu.kaynak, @"\ab04500-" + bilgisayar + @"" + DosyaYolu.hedef, true);
  85. if (copy)
  86. {
  87. kopya += 1;
  88. }
  89. else
  90. {
  91. sw.WriteLine(satir);
  92. }
  93. }
  94. catch (Exception)
  95. {
  96.  
  97. }
  98.  
  99. if (i == dongu)
  100. {
  101. sw.Close();
  102. MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information);
  103. lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString();
  104. }
  105.  
  106. bilgisayar += 1;
  107. }
  108.  
  109. }
  110.  
  111.  
  112. private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
  113. {
  114. sw = new StreamWriter(DateTime.Today.ToShortDateString().ToString() + "_ulasmayanlar.txt", true);
  115. StreamReader sr = new StreamReader(Application.StartupPath + @"savcilar.txt");
  116.  
  117. while ((satir = sr.ReadLine()) != null)
  118. {
  119. try
  120. {
  121. bool copy = CopyDirectory(DosyaYolu.kaynak, @"\" + satir + @"" + DosyaYolu.hedef, true);
  122. //bool copy = CopyDirectory(Application.StartupPath + @"TELEFON REHBERİ", @"\" + satir + @"c$Documents and SettingsAll UsersStart Menu", true);
  123. if (copy)
  124. {
  125. kopya += 1;
  126. }
  127. else
  128. {
  129. sw.WriteLine(satir);
  130. }
  131. }
  132. catch (Exception)
  133. {
  134.  
  135. }
  136. }
  137. }
  138.  
  139. private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  140. {
  141. sw.Close();
  142.  
  143. MessageBox.Show("İşlem tamamlandı", "İşlem Sonu", MessageBoxButtons.OK, MessageBoxIcon.Information);
  144. lblkopya.Text = "Başarıyla tamamlanan iş sayısı : " + kopya.ToString();
  145. }
Add Comment
Please, Sign In to add comment