473,750 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

BackgroundWorke r - 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 backgroundWorke r1_DoWork(objec t sender,
DoWorkEventArgs e)
{
String location = comboBox1.Text;

IPAddress newAddress = IPAddress.Parse (location);
byte[] fName =
ASCIIEncoding.A SCII.GetBytes(s fName.Substring (sfName.LastInd exOf('\\')
+ 1) + '\0');
FileStream file = null;

TcpClient Client = new TcpClient();
try
{
Client.Connect( newAddress, 5000);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Sender Error",
MessageBoxButto ns.OK, MessageBoxIcon. Error);
}

try
{
if (Client.Connect ed)
{
this.Text = "Sending File";
String line = null;
file = new FileStream(sfNa me, FileMode.Open);
fileLength = file.Length;
Client.Client.S end(fName, 0, fName.Length,
SocketFlags.Non e);

int BytesCount = 0;
mylegth = fileLength / 100;
long i = 0;
this.smoothprog ressBar1.Value = 0;
byte[] buffer = new byte[64];

BytesCount = file.Read(buffe r, 0, 64);
while ((BytesCount != 0))
{
i += Client.Client.S end(buffer, BytesCount,
SocketFlags.Non e);
this.smoothprog ressBar1.Value = (int)((i * 100)
/ fileLength);
BytesCount = file.Read(buffe r, 0, 64);
}
file.Close();
Client.Close();
this.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Sender Error",
MessageBoxButto ns.OK, MessageBoxIcon. Error);
}
finally
{
file.Close();
Client.Close();
}
}

Dec 18 '05 #1
1 3641
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******** *************@g 14g2000cwa.goog legroups.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 backgroundWorke r1_DoWork(objec t sender,
DoWorkEventArgs e)
{
String location = comboBox1.Text;

IPAddress newAddress = IPAddress.Parse (location);
byte[] fName =
ASCIIEncoding.A SCII.GetBytes(s fName.Substring (sfName.LastInd exOf('\\')
+ 1) + '\0');
FileStream file = null;

TcpClient Client = new TcpClient();
try
{
Client.Connect( newAddress, 5000);
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Sender Error",
MessageBoxButto ns.OK, MessageBoxIcon. Error);
}

try
{
if (Client.Connect ed)
{
this.Text = "Sending File";
String line = null;
file = new FileStream(sfNa me, FileMode.Open);
fileLength = file.Length;
Client.Client.S end(fName, 0, fName.Length,
SocketFlags.Non e);

int BytesCount = 0;
mylegth = fileLength / 100;
long i = 0;
this.smoothprog ressBar1.Value = 0;
byte[] buffer = new byte[64];

BytesCount = file.Read(buffe r, 0, 64);
while ((BytesCount != 0))
{
i += Client.Client.S end(buffer, BytesCount,
SocketFlags.Non e);
this.smoothprog ressBar1.Value = (int)((i * 100)
/ fileLength);
BytesCount = file.Read(buffe r, 0, 64);
}
file.Close();
Client.Close();
this.Dispose();
}
}
catch (Exception ex)
{
MessageBox.Show (ex.Message, "Sender Error",
MessageBoxButto ns.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
4855
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 I want to raise the ProgressChanged-event to update the DataGridView. It works fine when only one Progresschanged is fired, but at the second, third, fopurth etc it raises everytile a 'Cross-thread operation not valid"-exception on lmy...
5
14134
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 my FileIO class) I've established Public Event in my core logic classes along with RaiseEvents (that will updated a progress bar on the UI side). This all works great when I'm NOT using Threading (BackgroundWorker), however, as soon as I...
1
3230
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 progress event. So I added a bw to the form. The Dowork Calls a method which instantiates a DT and calls its Dataprocessing method.
9
5022
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 Catalog=MyDB;Data Source=MyServer;Integrated Security=True;". When I use the same connection string in my main thread of execution it works fine. However when I use that connection string in the newly created thread I get this exception: "Login...
8
16579
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 backgroundworker thread? Thanks, Randy
7
1750
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 Trace that prints always what bgw has unzipped and what ProgressChanged received: 1. bgw: HelpFilelistgzip 2. ProgressChanged: HelpFilelistgzip OK!
9
18029
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 will almost always lead to the user opening a certain child window that's fairly resource intensive to load. Is it possible to load this form in a backgroundworker and then use the Show method and hide method as necessary? Anyone know of
3
1685
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 object's value to 'true'). If i didn't have the locked object the thread was present in taskmanager even when application has been already gone. My question is:
4
2583
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 a separate thread. If the job is progressed it fires an event, and the main window handled the event by changing the value of a progress bar. The problem is that this event is fired in another thread so when the handler in the main window tries...
1
10392
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 CancelAsync, not cancels the call to COM. How I can do it , please ? Any suggestions will be very appreciated.
0
9000
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9396
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3322
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2225
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.