|
In the windows service, here is how I have setup the backgroundworker.
Question.
I do not know why the backgroundworker_progresschanged event does not get called.
Do you see what the problem is please?
Thanks
private BackgroundWorker backgroundWorker;
protected override void OnStart(string[] args)
{
backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker_ProgressChanged);
backgroundWorker.RunWorkerAsync();
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
}
|
|
|
|
|
|
I don't want to seem as though I'm being funny here, but how would it report progress. You have no functionality in your DoWork to report progress from. In your DoWork, you'd need to report progress using something like the following:
BackgroundWorker worker = sender as BackgroundWorker;
worker.ReportProgress(10);
|
|
|
|
|
Thanks for the reply...
I have read afew articles regarding the backgroundworker.
I am not sure if I am asking the correct question here, but my purpose is to make the backgroundworker to do some checking every few miliseconds.
1-
It seems to me that the checking has to be done in the progresschanged event. Am I correct?
2-
Where do I set the time interval in the backgroundworker?
Thank you
|
|
|
|
|
The purpose of the background worker is to run a task in the background. The purpose of the progress changed event is to indicate that some progress has been made, so you'd typically use this to update the UI to indicate that a task is working successfully. I wouldn't use a background worker for the purpose you want to - you'd be better off using a timer.
|
|
|
|
|
I did think about a timer at first but I do not think it is a good decision because of the following:
1-
There is a separate event which gets fired everytime a new message is received (i.e. every few milliseconds).
At this time, a collection is populated with the data being recieved in the above event.
2-
I am thinking of having a separate thread in the windows service to constantly check the collection and delete items where necessary...
What do you think?
Thanks
|
|
|
|
|
The checking can be done on the background thread which the DoWork event is called on and any updates to the UI can be done by reporting progress.
Two problems here:
Once the DoWork handler method returns then the RunWorkerCompleted event fires and the thread will be closed so you would either need to a. Ensure the DoWork handler never returns or b. start a new BackgroundWorker/restart from the RunWorkerCompleted handler. This is why Pete suggested a timer as it can raise an event on a background thread periodically for you.
The background thread is going to be chewing up processor cycles if you just loop in your DoWork handler - this isn't a good idea! Sleeping the thread on each loop may be a quick solution to this - but still a timer makes more sense.
|
|
|
|
|
|
hi,
I have a MDI Parent From, MDI Child Form & a third Dialog Form.
I call a third Form by clicking a button using ShowDialog() placed in MDI Child.
I like to refresh MDI Child after closing that third Form...
but after closing of third Form,
MDI Parent fired Activated event instead of MDI Child ...!
Give the solution...
|
|
|
|
|
Manish_84 wrote: I call a third Form by clicking a button using ShowDialog() placed in MDI Child.
I like to refresh MDI Child after closing that third Form...
The ShowDialog method is blocking; you can refresh your MDI child right after the line where you show the dialog. Once the dialog is closed, execution will continue there.
Manish_84 wrote: Give the solution...
I are Troll
|
|
|
|
|
please advice me a simlple unzip method in C#
other than using Shell object...
note : zip file contains files and multiple folders
modified on Wednesday, January 5, 2011 1:57 AM
|
|
|
|
|
|
this will help me to unzip multiple folders??
|
|
|
|
|
Yes it is.
If you can unzip one folder then further you can unzip any number of folders, There are lot of features in a language of looping, Just change your program accordingly.
|
|
|
|
|
thanks
i will try hiren .. will let you know
|
|
|
|
|
me too. I have a project but It's don't work in this case.
|
|
|
|
|
|
thanks a lot ravi
its working
|
|
|
|
|
you are always welcome.
|
|
|
|
|
|
Is this a question?
Or is this an instruction?
If the former, then you forgot to include the bit explaining what your problem is.
If the later, you forgot you are not my employer.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
actually i struck in implementing site map by using recursion concept.
i need to develop user control for sitemap by using recursion if you have idea on that please let me know.
thanks.
|
|
|
|
|
What have you tried?
How far have you got?
Where are you stuck?
Sorry, but without these it is difficult to be at all specific!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
|
Couple of things:
1) When you post code fragments, use the "code block" widget not the "inline code" (That way you get <pre> tags instead of <code> tags. This preserves your formatting
inline code:
string SubUlHTML = "";<br />
if (node.HasChildNodes)<br />
{<br />
SubUlHTML = "<ul>";<br />
foreach (SiteMapNode childnode in node.ChildNodes)<br />
{<br />
SubUlHTML += GetNodeHTML(childnode);
code block:
string SubUlHTML = "";
if (node.HasChildNodes)
{
SubUlHTML = "<ul>";
foreach (SiteMapNode childnode in node.ChildNodes)
{
SubUlHTML += GetNodeHTML(childnode); Which would you rather read?
2) Looping isn't recursion. Recursion: See "Recursion".
For example: Factorials
In mathematics, the factorial of a positive integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
5! = 5 x 4 x 3 x 2 x 1
0! is a special case that is explicitly defined to be 1.
Another way to write that is n! = n * (n-1)! while n > 1
To code this:
private int Factorial (int n)
{
if (n < 0)
{
throw new ArgumentException("Factorial not defined for negative numbers");
}
if (n == 0)
{
return 1;
}
return n * Factorial(n - 1);
}
Do you see the difference between that an a loop? If not, think about it. This is important!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|