Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey all,

I have issue with backgroundworker:

1-I am working on mobile application and the CF do not support backgroundworker
2- I got the dll. for Backgroundworker from this site http://www.danielmoth.com/Blog/backgroundworker-for-cf-10.aspx
3- I tried this code:-

BackgroundWorker bw; 
bw = new BackgroundWorker(); 
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.RunWorkerAsync(); 
void bw_Dowork () 
{
    int i=0; do
    {
        system.writeline("1"); 
    }while(i==0); 
}


This part of code perform the function in bw_Dowork but still not able to run other function with it like if i have button in form I can't able to click on the button because application perform other operation ?
Any idea for this ??!!

If you have any other method or way to perform function but make application free to control and clicks and perform other function
Posted
Updated 28-Jun-10 3:31am
v3

1 solution

I'm not sure if it works with mobile applications, but try putting a Sleep() or DoEvents() inside your do loop...
 
Share this answer
 
Comments
Ashraf ELHakim 28-Jun-10 10:16am    
thx for ur replay but i dnt now why i put sleep() in my loop and i wannaa this loop to be infity loop !
but ir try it and no changes
Johnny J. 28-Jun-10 10:23am    
First of all: Infinite loops are not good programming practice. If you insist on having an infinite loop in your background worker, then you need to set WorkerSupportsCancellation= true, cancel the worker when your program shuts down and in the do loop you must check if cancellation is required and exit the loop if it is. Otherwise you will not be able to shut down the application properly, and windows will not be able to shut it either when e.g. a reboot is required.

Second of all: Because your loop is running round, round, it is not giving other threads permission to run. Hence the Sleep. What sleep-value did you use? If you haven't already, add a "using System.Threading;", and in your do loop you put "Thread.Sleep(500);" (for instance) - that will make your thread sleep for 500 ms, thus allowing other threads to run. Hopefully that should work. Otherwise I'm open for suggestions too...
Ashraf ELHakim 28-Jun-10 11:24am    
yeeeeeees thxxxxxxx it is work :)
Special thx from me
sry i dnt understood the sleep what mean ?? but now i undertand :)
thxxxxxx
Johnny J. 28-Jun-10 12:58pm    
No problem - glad to have been of help... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900