Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
4.20/5 (3 votes)
See more:
Hi guys
I'm new to C# threads so forgive me If you feel my question is very simple.Can we call a function in thread who has parameters in it? Thanks in advance.
Posted
Updated 27-Dec-13 21:58pm
v3

Yes. Exactly as you would from the "normal" UI thread - all code runs on a thread, so it doesn't matter which thread you call a method from: if it returns a string, it returns a string to the caller on the same thread.
C#
private void button1_Click(object sender, EventArgs e)
    {
    BackgroundWorker work = new BackgroundWorker();
    work.DoWork += new DoWorkEventHandler(work_DoWork);
    work.RunWorkerAsync();
    }

void work_DoWork(object sender, DoWorkEventArgs e)
    {
    Console.WriteLine(GetMyString());
    }
string GetMyString()
    {
    return DateTime.Now.ToString();
    }
 
Share this answer
 
Comments
agent_kruger 28-Dec-13 3:59am    
can you tell difference between backgroundworker and a thread?
OriginalGriff 28-Dec-13 4:03am    
Well, they are spelled differently, which is a big clue...:laugh:
agent_kruger 28-Dec-13 4:06am    
oh, thank you for that precious little peace of information.
agent_kruger 28-Dec-13 4:06am    
without you i would be stuck in that problem for the whole life :laugh.
OriginalGriff 28-Dec-13 4:20am    
Glad to oblige! :laugh:

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