473,378 Members | 1,330 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

BackgroundWorker - have no idea

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(sfNa me.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();
}
}

Dec 18 '05 #1
1 3622
Not being a great expert on this you may want to confirm but I've had
similar concerns with running Excel from .NET code. I think the system
wants to decide when to terminate the process. I'd start Excel and try to
shut it down when finished, Excel and try to shut it down when finished,
over and over. The system would have 5 or so Excel processes running before
it decided to terminate one. Similar things happen with memory management.

David
"Piotrekk" <Pi*************@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
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(sfNa me.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();
}
}

Dec 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pieter | last post by:
Hi, I'm having some weird problem using the BackGroundWorker in an Outlook (2003) Add-In, with VB.NET 2005: I'm using the BackGroundWorker to get the info of some mailitems, and after each item...
5
by: Rob R. Ainscough | last post by:
I'm using a BackgroundWorker to perform a file download from an ftp site. Per good code design practices where I separate my UI code from my core logic code (in this case my Download file method in...
1
by: Bob | last post by:
Hi, I am having trouble seeing how this bolts together. The UI starts a process which involves a long running database update. All Database activity is handled by a class called DT. DT has a...
9
by: =?Utf-8?B?VE9NX1Bhc2FkZW5h?= | last post by:
Hello, In my ASP.Net app I'm launching a BackgroundWorker thread in my Page_Load function. In that thread I'm attempting to connect to a SQL server using this connection string "Initial...
8
by: =?Utf-8?B?cmFuZHkxMjAw?= | last post by:
I have an application with several BackgroundWorker threads. I hoped I'd be able to just type backgroundworker1.Name = "bw1"; but I don't see a name property. Any thoughts on how to name a...
7
by: =?Utf-8?B?SGVucnk5OQ==?= | last post by:
What happens here? The backgroundworker (bgw) unzips RTF-Helpfiles (up to 1 MB in size). The ProgressChanged-Event gets the unzipped files (to display them in a RichtTextBox) It follows the...
9
by: RvGrah | last post by:
I'm completely new to using background threading, though I have downloaded and run through several samples and understood how they worked. My question is: I have an app whose primary form...
3
by: Piotrekk | last post by:
I have a question. One day i have been working with threads. Thread had 'while' loop that checked locked value telling the thread when application was closing ( in Dispose method i set locked...
4
by: Sin Jeong-hun | last post by:
This is what I've always been wondered. Suppose I've created a class named Agent, and the Agent does some lengthy job. Of course I don't want to block the main window, so the Agent does the job in...
1
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi misters, Is it possible "kill" the thread of Backgroundworker ? In my Dowork event, I have NOT While for do e.Cancel = true, only have a call to external COM. If I want cancel, calling...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.