473,387 Members | 1,407 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,387 software developers and data experts.

ThreadStart

Can put a method with parameter in the ThreadStart ?

Thread bThread = new Thread(new ThreadStart(Function(Parameter))); // Not Ok why? another way maybe ?

Max
Nov 15 '05 #1
3 2955
No. Here's a link to do what you want.
http://tinyurl.com/27za3

--
Regards,
Alvin Bruney
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"Maxime" <ma*************@sympatico.ca> wrote in message
news:RN*******************@news20.bellglobal.com.. .
Can put a method with parameter in the ThreadStart ?

Thread bThread = new Thread(new ThreadStart(Function(Parameter))); // Not Ok
why? another way maybe ?

Max
Nov 15 '05 #2
Maxime <ma*************@sympatico.ca> wrote:
Can put a method with parameter in the ThreadStart ?

Thread bThread = new Thread(new ThreadStart(Function(Parameter)));
// Not Ok why? another way maybe ?


See http://www.pobox.com/~skeet/csharp/threadstart.html

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
ed
"Maxime" <ma*************@sympatico.ca> wrote in message news:<RN*******************@news20.bellglobal.com> ...
Can put a method with parameter in the ThreadStart ?

Thread bThread = new Thread(new ThreadStart(Function(Parameter))); //
Not Ok why? another way maybe ?

Max


Max,

You can't pass parameter info, to pass data between the threads have a
look at the example:

http://msdn.microsoft.com/library/de...ingthreads.asp

in the section "Passing Data To Threads"

basically the sample is:

[C#]
using System;
using System.Threading;

// The ThreadWithState class contains the information needed for
// a task, and the method that executes the task.
//
public class ThreadWithState {
// State information used in the task.
private string boilerplate;
private int value;

// The constructor obtains the state information.
public ThreadWithState(string text, int number) {
boilerplate = text;
value = number;
}

// The thread procedure performs the task, such as formatting
// and printing a document.
public void ThreadProc() {
Console.WriteLine(boilerplate, value);
}
}

// Entry point for the example.
//
public class Example {
public static void Main() {
// Supply the state information required by the task.
ThreadWithState tws =
new ThreadWithState("This report displays the number
{0}.", 42);
// Create a thread to execute the task, and then
// start the thread.
Thread t = new Thread(new ThreadStart(tws.ThreadProc));
t.Start();
Console.WriteLine("Main thread does some work, then waits.");
t.Join();
Console.WriteLine("Independent task has completed; main thread
ends.");
}
}

ed
Nov 15 '05 #4

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

Similar topics

2
by: Victor Hadianto | last post by:
Hello, Can someone explain to me why are we not allowed to have a parameter on the ThreadStart delegate? Does anyone know the design decision behind this feature? This, IMO, rather annoying when...
2
by: n_o_s_p_a__m | last post by:
I run my multithreaded classes (class library) in a standard exe host, works with no problems; but once hosted in SCM, the threads are not spawned, yet no exceptions are thrown. Is this some kind...
4
by: Fernando Rodríguez | last post by:
Hi, ThreadStart doesn't take any parameters. How can I create threads that take parameters? O:-) Thanks
2
by: StefanS | last post by:
Hi all I'm stuck with a problem and hope someone can provide some hints on what I'm doing wrong. All I want to do ist start a thread which will sleep until a specified time and then wake up...
2
by: Ryan Liu | last post by:
How a thread is reused in thread pool? Change the context and call theThread.Run() again, and it executes same threadStart? Thanks! Ryan
4
by: Mike P | last post by:
How do you pass your parameters to the method you have specified for the threadstart? System.Threading.ThreadStart thdStart = new System.Threading.ThreadStart(MoveMail(new object { progress,...
10
Airslash
by: Airslash | last post by:
Hello, I'm aware that the code I'm currently using is far from perfect. I'm not even sure if it does exactly what it is supposed to do, but I'm trying to do the following: My Resources class,...
1
by: robparr | last post by:
Hello, hopefully someone can help me. I am reading and learning steadily about threading and asynchronous programming, which to me sound like the same thing. At the moment I am not sure what the...
1
by: ktrvnbq02 | last post by:
Hi, I recently came to debug some old code that was causing a StackOverflowException. The code in question makes significant use of recursion and with large data structures it exhausted the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.