P
Piotrekk
Hi
I'am trying to force my background worker to finish, but i can't - its
still visible in windows processes.
have no idea why it's still there when file is sent.
Code is clear and visible so i wish someone could help me.
Thanks
PK
Here is the code:
private void backgroundWorker1_DoWork(object sender,
DoWorkEventArgs e)
{
String location = comboBox1.Text;
IPAddress newAddress = IPAddress.Parse(location);
byte[] fName =
ASCIIEncoding.ASCII.GetBytes(sfName.Substring(sfName.LastIndexOf('\\')
+ 1) + '\0');
FileStream file = null;
TcpClient Client = new TcpClient();
try
{
Client.Connect(newAddress, 5000);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Sender Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
if (Client.Connected)
{
this.Text = "Sending File";
String line = null;
file = new FileStream(sfName, FileMode.Open);
fileLength = file.Length;
Client.Client.Send(fName, 0, fName.Length,
SocketFlags.None);
int BytesCount = 0;
mylegth = fileLength / 100;
long i = 0;
this.smoothprogressBar1.Value = 0;
byte[] buffer = new byte[64];
BytesCount = file.Read(buffer, 0, 64);
while ((BytesCount != 0))
{
i += Client.Client.Send(buffer, BytesCount,
SocketFlags.None);
this.smoothprogressBar1.Value = (int)((i * 100)
/ fileLength);
BytesCount = file.Read(buffer, 0, 64);
}
file.Close();
Client.Close();
this.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Sender Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
file.Close();
Client.Close();
}
}
I'am trying to force my background worker to finish, but i can't - its
still visible in windows processes.
have no idea why it's still there when file is sent.
Code is clear and visible so i wish someone could help me.
Thanks
PK
Here is the code:
private void backgroundWorker1_DoWork(object sender,
DoWorkEventArgs e)
{
String location = comboBox1.Text;
IPAddress newAddress = IPAddress.Parse(location);
byte[] fName =
ASCIIEncoding.ASCII.GetBytes(sfName.Substring(sfName.LastIndexOf('\\')
+ 1) + '\0');
FileStream file = null;
TcpClient Client = new TcpClient();
try
{
Client.Connect(newAddress, 5000);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Sender Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
try
{
if (Client.Connected)
{
this.Text = "Sending File";
String line = null;
file = new FileStream(sfName, FileMode.Open);
fileLength = file.Length;
Client.Client.Send(fName, 0, fName.Length,
SocketFlags.None);
int BytesCount = 0;
mylegth = fileLength / 100;
long i = 0;
this.smoothprogressBar1.Value = 0;
byte[] buffer = new byte[64];
BytesCount = file.Read(buffer, 0, 64);
while ((BytesCount != 0))
{
i += Client.Client.Send(buffer, BytesCount,
SocketFlags.None);
this.smoothprogressBar1.Value = (int)((i * 100)
/ fileLength);
BytesCount = file.Read(buffer, 0, 64);
}
file.Close();
Client.Close();
this.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Sender Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
file.Close();
Client.Close();
}
}