Backgroundworker

P

Patrick

Hi,

I'm working on a problem with the Backgroundworker since days. Maybe you can
help me to understand it.
I've a Backgroundworker, which calls a new class and executes a method:

protected override void OnDoWork(DoWorkEventArgs e)
{
CheckSomething cs = new CheckSomething();
cs.Check(e.Argument);
somethingelse = e.Result;
}

The problem is, that I'm insert the result from cs.check from OnDoWork to an
datagridview, but the Results are disordered with other Backgroundworker
Threads.
What is wrong?

The cs.Check class includes a webrequest wo calls a Servicepointer.
The results of the webrequest and the servicepointer were send back to the
OnDoWork Event.

I hope you can follow me and help me.

br,
patrick
 
P

Patrick

Peter Duniho said:
[...]
protected override void OnDoWork(DoWorkEventArgs e)
{
CheckSomething cs = new CheckSomething();
cs.Check(e.Argument);
somethingelse = e.Result;
}

The problem is, that I'm insert the result from cs.check from OnDoWork
to an
datagridview, but the Results are disordered with other Backgroundworker
Threads.
What is wrong?

Impossible to say with such a vague question. BackgroundWorker tasks are
not inherently ordered in the first place, so saying that the results from
BackgroundWorker tasks are out of order doesn't make any sense.

If you want a specific order, then you need to implement that yourself.
How best to do that depends a lot on what order you want, how you define
it, and what your _actual_ code looks like. Without those details, it's
not possible to provide any better information.

Pete

Hi,

thanks for the answer!
The problem is not the order structure in the datagridview. The problem is,
that I get a value from the first backgroundworker thread in datagridcolumn
one and one value of another thread in datagridcolumn two.

My code looks like this:

class BGWorker : BackgroundWorker
{
protected override void OnDoWork(DoWorkEventArgs e)
{
CheckSomething cs = new CheckSomething ();
int web = (int)e.Argument;
cs.Check(web);
string[] sArray = new string[3];
e.Result = sArray;
}
}
-------------------------------------------------
public class CheckSSL
{
public Boolean ValidateCert(object sender, X509Certificate cert,
X509Chain ch, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors ==
SslPolicyErrors.RemoteCertificateChainErrors || sslPolicyErrors.ToString() ==
"RemoteCertificateNameMismatch, RemoteCertificateChainErrors")
CertError("Chain Error");
if (sslPolicyErrors ==
SslPolicyErrors.RemoteCertificateNameMismatch || sslPolicyErrors.ToString()
== "RemoteCertificateNameMismatch, RemoteCertificateChainErrors")
CertError("Certificate name mismatch");
if (sslPolicyErrors.ToString() ==
"RemoteCertificateNameMismatch, RemoteCertificateChainErrors")
CertError("ChainError&NameMismatch");
if (sslPolicyErrors ==
SslPolicyErrors.RemoteCertificateNotAvailable)
CertError("Certificate not available");
if (sslPolicyErrors == SslPolicyErrors.None)
CertError("OK");
Cert_Date = cert.GetExpirationDateString();
}

public string[] Check(object website)
{
string sWebSite = WebSites.webs[(int)website].ToString();
ServicePointManager.ServerCertificateValidationCallback
= new RemoteCertificateValidationCallback(ValidateCert);
WebRequest myRequest = WebRequest.Create(sWebSite);
myRequest.Timeout = 1000;
myResponse = myRequest.GetResponse();

stringArray[0] = sWebSite;
stringArray[1] = Cert_Date;
stringArray[2] = CertError;
}
--------------------------------------

And now when get back this 3 values, I always get the the wrong date to the
wrong Website.

br,
patrick
 
G

Gaston Hillar

You can check my article in Packt's website:
http://www.packtpub.com/article/simplifying-parallelism-complexity-c-sha
rp
You can also download code examples from my book "C# 2008 and 2005
threaded programming", in
http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-thread
ed-programming

In this book, you will find many topics related to updating the UI from
independent threads created by many different methods. They'll be very
usuful for you to solve your problem. Updating the UI from many
independent threads is one of the most difficult things to learn when
programming using many concurrent threads. I would need some diagrams to
explain you that. The book will do it for me :)
 
G

Gaston Hillar

You can check my article in Packt's website:
http://www.packtpub.com/article/simplifying-parallelism-complexity-c-sha
rp
You can also download code examples from my book "C# 2008 and 2005
threaded programming", in
http://www.packtpub.com/beginners-guide-for-C-sharp-2008-and-2005-thread
ed-programming

In this book, you will find many topics related to updating the UI from
independent threads created by many different methods. They'll be very
usuful for you to solve your problem. Updating the UI from many
independent threads is one of the most difficult things to learn when
programming using many concurrent threads. I would need some diagrams to
explain you that. The book will do it for me :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top