Need help with threading
-
Hi im new at these forums, so this is my first post, i hope that some of you guys could help me out with this problem i have. I'm building a drag n' drop program that will allow a user to drag n drop an item (like a button) from one control to another. Currently i have a problem managing threads, or rather parsing data between them. My problem is this. I need to sample the mouse's x and y coordinates for each control so that it will drop the item at the correct place in the control. The reason im using threading is that once i start dragging an object (button) the sampling of the x and y coordinates pauses. Thus i need to run it in another thread. My problem is that i can't seem to get _GetLocalMouseCoordinates to run in a thread of its own, i get this error C:\Documents and Settings\My Documents\Visual Studio Projects\DragNDrop\DragDrop.cs(359): Method 'DragNDrop.Form1._GetLocalMouseCoordinates(object, System.Windows.Forms.MouseEventArgs)' does not match delegate 'void System.Threading.ThreadStart()' The code is below, i have only pasted the "vital" part though. I hope that someone cna help. Thanks alot in advance! using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; namespace DragNDrop { /// /// Summary description for Form1. /// /// Huske/tænke liste /// /// 1. Threading hvor hurtig opdaterings tid kan formen klare uden at choke? /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Panel pnlDrag; private System.Windows.Forms.Panel pnlDrop; private System.Windows.Forms.Label lblDrag; private System.Windows.Forms.Label lblDrop; private System.Windows.Forms.Button btnDrag; private System.Windows.Forms.Button btnPush; private System.Windows.Forms.StatusBar statusBarGlobal; private System.Windows.Forms.StatusBar statusBarLocalDrop; private System.Windows.Forms.StatusBar statusBarLocalDrag; // My generated variables etc. public int iXCoorDrag; public int iYCoorDrag; public int iXCoorDrop; public int iYCoorDrop; public int iXCoorGlobal; public int iYCoorGlobal; public Thread GlobalMouseThread; public Thread LocalMouseThread; public bool bStopthread; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Design
-
Hi im new at these forums, so this is my first post, i hope that some of you guys could help me out with this problem i have. I'm building a drag n' drop program that will allow a user to drag n drop an item (like a button) from one control to another. Currently i have a problem managing threads, or rather parsing data between them. My problem is this. I need to sample the mouse's x and y coordinates for each control so that it will drop the item at the correct place in the control. The reason im using threading is that once i start dragging an object (button) the sampling of the x and y coordinates pauses. Thus i need to run it in another thread. My problem is that i can't seem to get _GetLocalMouseCoordinates to run in a thread of its own, i get this error C:\Documents and Settings\My Documents\Visual Studio Projects\DragNDrop\DragDrop.cs(359): Method 'DragNDrop.Form1._GetLocalMouseCoordinates(object, System.Windows.Forms.MouseEventArgs)' does not match delegate 'void System.Threading.ThreadStart()' The code is below, i have only pasted the "vital" part though. I hope that someone cna help. Thanks alot in advance! using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Threading; namespace DragNDrop { /// /// Summary description for Form1. /// /// Huske/tænke liste /// /// 1. Threading hvor hurtig opdaterings tid kan formen klare uden at choke? /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Panel pnlDrag; private System.Windows.Forms.Panel pnlDrop; private System.Windows.Forms.Label lblDrag; private System.Windows.Forms.Label lblDrop; private System.Windows.Forms.Button btnDrag; private System.Windows.Forms.Button btnPush; private System.Windows.Forms.StatusBar statusBarGlobal; private System.Windows.Forms.StatusBar statusBarLocalDrop; private System.Windows.Forms.StatusBar statusBarLocalDrag; // My generated variables etc. public int iXCoorDrag; public int iYCoorDrag; public int iXCoorDrop; public int iYCoorDrop; public int iXCoorGlobal; public int iYCoorGlobal; public Thread GlobalMouseThread; public Thread LocalMouseThread; public bool bStopthread; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Design
eclipsedk wrote: C:\Documents and Settings\My Documents\Visual Studio Projects\DragNDrop\DragDrop.cs(359): Method 'DragNDrop.Form1._GetLocalMouseCoordinates(object, System.Windows.Forms.MouseEventArgs)' does not match delegate 'void System.Threading.ThreadStart()' Ahhh, a more decriptive error there could not be. I can't judge the rightness of your overall algorithm, but the problem here is that you're trying to start a method that does not match the parameter list and return value specified by the
ThreadStart
delegate http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemthreadingthreadstartclasstopic.asp[^]. You can only start methods using that delegate that returnvoid
and accept no parameters._GetGlobalMouseCoordinates
matches the delegate._getLocalMouseCoordinates
on the other hand, wants anobject
and aMouseEventArgs
. Share and enjoy. Sean