473,383 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

backgroundworker and generics

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
Apr 27 '06 #1
4 3257
Tommaso Caldarola <il********@lcimitero.it> wrote:
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
Apr 27 '06 #2
Barry Kelly wrote:
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.


I get the following error

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

--

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Apr 28 '06 #3
Barry Kelly wrote:
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.


I get the following error

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

--

Inviato da X-Privat.Org - Registrazione gratuita http://www.x-privat.org/join.php
Apr 28 '06 #4
Tommaso Caldarola <il********@lcimitero.it> wrote:
Barry Kelly wrote:
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.


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
Apr 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: dm1608 | last post by:
Hi -- I have a C# application that basically has a button that executes a SQL Reader to loop thru a rather large resul set. Thru each interation of the reader object, I check to see if a file...
5
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...
1
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...
14
by: =?Utf-8?B?SXNobWFlbA==?= | last post by:
Hi, I have a form with a progress bar on it and wanted to use the BackgroundWorker to be able to update the progress. I looked at examples, run some of them, but in debug, when the code gets to...
0
by: Chris | last post by:
I would like to be able to pass the BackgroundWorker object and DoWork Event Args to a second function (third function?) and be able to still report the progress. I'm getting the following...
2
by: Chris | last post by:
When I try to access the backgroundWorker.CancellationPending property I get the following exception: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in...
9
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...
4
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...
2
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have introduced a component to my solution that is throwing an exception about needing to be run in single threaded apartment mode. This component is created in an async call by a...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.