backgroundworker and generics

T

Tommaso Caldarola

What do I pass as argument in order to get generics type from e.Argument in DoWork?

backgroundWorker.RunWorkerAsync(????);

void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
MyMtehod<????>();
}


MyMethod<T>();


Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
 
B

Barry Kelly

Tommaso Caldarola said:
What do I pass as argument in order to get generics type from e.Argument in DoWork?

backgroundWorker.RunWorkerAsync(????);

void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
MyMtehod<????>();
}


MyMethod<T>();

You could pass an anonymous delegate as e.Argument to the background
worker instead.

-- Barry
 
T

Tommaso Caldarola

Barry said:
You could pass an anonymous delegate as e.Argument to the background
worker instead.

I get the following error

"cannot convert from 'anonymous method' to 'object'"
 
B

Barry Kelly

Tommaso Caldarola said:
I get the following error

"cannot convert from 'anonymous method' to 'object'"

You could do it like:

---8<---
delegate void MyMethod();

// ...
backgroundWorker.RunWorkAsync((MyMethod) delegate
{
// the code...
});

void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
((MyMethod) e.Argument)();
}
--->8---

-- Barry
 

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