Error 1 No Overload For Matches Delegate System Threading Threadstart
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this c# parameterizedthreadstart site About Us Learn more about Stack Overflow the company Business Learn
C# Thread With Parameters
more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
C# Task
x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up No overload for '' matches delegate 'System.Threading.ParameterizedThreadStart' up vote 1 down vote favorite If i have a method like this private void LoadModel(List
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up No overload for 'textBox1_TextChanged_1' matches delegate 'System.Threading.TimerCallback up vote http://stackoverflow.com/questions/33137039/no-overload-for-matches-delegate-system-threading-parameterizedthreadstart 0 down vote favorite I want to use System.Threading.Timer so that I can use this timer to call method "CreateThread" which is as follows. public void CreateThread() { th1 = new Thread(ChangeLabel); th1.Start(); } I am getting error at line: public void textBox1_TextChanged_1(object sender, EventArgs e) { TimerCallback tcb = new TimerCallback(CreateThread); //This line is showing error } Can anybody please explain what is the problem? c# multithreading http://stackoverflow.com/questions/23632992/no-overload-for-textbox1-textchanged-1-matches-delegate-system-threading-time share|improve this question asked May 13 '14 at 13:44 DotNetNewBie 18910 add a comment| 3 Answers 3 active oldest votes up vote 1 down vote accepted TimerCallback expects a state property in the delegate: public void CreateThread(object state) { th1 = new Thread(ChangeLabel); th1.Start(); } MSDN: public delegate void TimerCallback( Object state ) share|improve this answer answered May 13 '14 at 13:48 Patrick Hofman 82.4k1479125 add a comment| up vote 0 down vote The problem is your method signature doesn't match with the TimerCallback delegate.It takes an object as parameter, but your method takes nothing. share|improve this answer answered May 13 '14 at 13:47 Selman Genc 68.7k84293 add a comment| up vote 0 down vote If you look at the MSDN Documentation for the TimerCallback delegate, you will see that it has a signature of void TimerCallback(object). The method you want the timer to call needs the same signature so that it will compile. Something like this would fix it: public void CreateThread() { CreateThread(null); } private void CreateThread(object state) { th1 = new Thread(ChangeLabel); th1.Start(); } This would allow any existing callers of CreateThread() to remain unchanged, whilst giving you a method with the correct signature to call the method. Alt
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow http://stackoverflow.com/questions/811224/how-to-create-a-thread the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of http://www.dreamincode.net/forums/topic/284710-no-overload-matches-delegate-systemthreadingthreadstart/ 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up How to create a thread? up vote 18 down vote favorite 2 The method below is what I error 1 want to be done in that thread: public void Startup(int port,string path) { Run(path); CRCCheck2(); CRCCheck1(); InitializeCodeCave((ushort)port); } I tried what I could find googling,but nothing worked public void Test(int port,string path) { Thread t = new Thread(Startup(port,path)); } public void TestA(int port,string path) { Thread t = new Thread(Startup); t.Start (port,path); } Both don't compile,how to do that? c# multithreading share|improve this question edited Sep 10 '15 at 8:33 shytikov 4,16732863 asked error 1 no May 1 '09 at 12:52 Ivan Prodanov 10.4k50134218 1 doesn't work, or doesn't compile? –Aziz May 1 '09 at 12:57 You should specify the language used so that I (we) don't have to guess. Also saying, what doesn't work would be great. –tuergeist May 1 '09 at 13:00 1 Check the question tags - C# It doesn't compile. –Ivan Prodanov May 1 '09 at 13:03 The language is spec'd in the tag. :) –Greg D May 1 '09 at 13:03 add a comment| 5 Answers 5 active oldest votes up vote 35 down vote accepted The following ways work. // The old way of using ParameterizedThreadStart. This requires a // method which takes ONE object as the parameter so you need to // encapsulate the parameters inside one object. Thread t = new Thread(new ParameterizedThreadStart(StartupA)); t.Start(new MyThreadParams(path, port)); // You can also use an anonymous delegate to do this. Thread t2 = new Thread(delegate() { StartupB(port, path); }); t2.Start(); // Or lambda expressions if you are using C# 3.0 Thread t3 = new Thread(() => StartupB(port, path)); t3.Start(); The Startup methods have following signature for these examples. public void StartupA(object parameters); public void StartupB(int port, string path); share|improve this answer edited May 1 '09 at 13:42 answered May
1 of 1 New Topic/Question Reply 2 Replies - 7547 Views - Last Post: 04 July 2012 - 07:29 AM Rate Topic: #1 paperclipmuffin Disassembling... Reputation: 13 Posts: 944 Joined: 16-April 09 No overload matches delegate 'System.Threading.ThreadStart' Posted 03 July 2012 - 08:16 PM Hi again, I have a static class used for processing server strings: using System; using System.IO; using System.Threading; namespace AuthServer { public static class HeartbeatHandler { static int tablesize; static bool hasTableSize = false; private static void getTableSize() { tablesize = File.ReadAllLines(Environment.CurrentDirectory + "\\cidata.txt").Length; hasTableSize = true; } public static void Handle(NPHandler client, string data) { if (!hasTableSize) { getTableSize(); } Log.Data("Received heartbeat: " + data); if (!client.RunningHeartbeat) { client.LastHeartbeat = 0; ThreadStart watch = new ThreadStart(WatchClass.WatchHeartbeat); Thread watcher = new Thread(watch); watcher.Start(client); client.RunningHeartbeat = true; } string[] splitData = data.Split(' '); client.SessionID = int.Parse(splitData[1]); if (int.Parse(splitData[2]) != 11) { CIHandler.Handle(client, "CI_Detection " + splitData[2]); } if (int.Parse(splitData[3]) != tablesize) { Log.Data("Sending CIData to client at " + client.Address.ToString()); SendCIData(client); client.HasCIData = true; } } private static void SendCIData(NPHandler client) { byte[] raw = File.ReadAllBytes(Environment.CurrentDirectory + "\\cidata.txt"); } private static byte[] encrypt(byte[] data, byte[] key) { return data; } } public static class WatchClass { public static void WatchHeartbeat(NPHandler client) { while (client != null) { if (client.LastHeartbeat > 89) { client.CloseConnection(false); client.RunningHeartbeat = false; return; } client.LastHeartbeat++; Thread.Sleep(1000); } } } } However the line ThreadStart watch = new ThreadStart(WatchClass.WatchHeartbeat); throws an error: No overload for '