|
try to avoid using Abort to stop the thread. Use flag to abort the thread.
I got a lot of problem using Abort.
while(isThreadRunning)
{
...
}
to stop it, set isThreadRunning = false;
|
|
|
|
|
Note: you must declare isThreadRunning as volatile, or it will be optimised out...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
well, my friend, if u see i have used
ThreadPool.QueueUserItem(...);
How should i get rid of this to stop all threads.
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
You must implement the code, that I sent, in these methods:
pdfDownloadStart
startXMLDownload
Then set isThreadRunning=false to end the thread.
|
|
|
|
|
well, i think u guys did not understand me correctly, bellow is the complete code only for "pdfDownloadStart"
void StartStructureTimer(int time)
{
timStructure=new System.Threading.Timer(new TimerCallback(TimerStructureJob));
timStructure.Change(time,0);
}
void TimerStructureJob(object state)
{
System.Threading.Timer tm=state as System.Threading.Timer;
tm.Dispose();
pdfDownloadStart();
}
void pdfDownloadStart()
{
try
{
signalMessage(string.Format("Searching Server {0} for newly added Files",fdo.FtpServer));
dtList=p.getPdfNotDownloaded();
if (dtList.Rows.Count>0)
{
signalMessage(string.Format("{0} Files Found for Download",dtList.Rows.Count));
fdo.FilesToDownloadList=dtList;
fdo.LocalDownloadDirectory=TempDirectory;
Thread tPdf=new Thread(new ThreadStart(downloadFile));
tPdf.Start();
tPdf.Join();
if (!fdo.DownloadStatus)
{
if (timDownload!=null)
timDownload.Dispose();
signalMessage("Download Failed\r\nretrying in 60 second");
StartTimer(36000);
}
else if (fdo.DownloadStatus)
{
if (timDownload!=null)
timDownload.Dispose();
signalMessage("All Files Downloaded Successfully\r\nretrying in 60 second");
StartTimer(36000);
return;
}
else
StartTimer(36000);
}
else
{
signalMessage("No Files Found\r\nretrying in 60 second");
StartTimer(36000);
}
}
catch(Exception ex)
{
if (!pdfStopped)
{
signalMessage("Failed downloading Files from Remote Server "+ex.Message+"\r\nretrying in 60 second");
StartTimer(36000);
}
else
signalMessage("Failed downloading Files from Remote Server "+ex.Message);
}
}
all methods which runs on those thread has the same functionality. if u see after "60 second" process runs agains.
if i abort or stop the thread still the job runs after 60 seconds.
if u see closly another thread is running to download the files, well i want to stop all these threads, if i use bool value like that still the scheduled process runs.
how can i stop all these threads from calling thread to end?
Abdul Rahaman Hamidy
Database Developer
Kabul, Afghanistan
|
|
|
|
|
Hmm.. I think you should redesign it. You start a threadpool, in threadpool you start a thread, in that thread you start a thread again.. wow..
|
|
|
|
|
Try here: How to create and terminate threads[^]
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Since you've set the IsBackground property to true, those threads get aborted when the program closes. Alternatively, you could all pdfThread.Stop, etc.
Between the idea
And the reality
Between the motion
And the act
Falls the Shadow
|
|
|
|
|
Hi all,
I am busy developing a custom TCP/IP server. The server has a few events namely, NewTcpData, NewTcpClient and TcpClientDisconnected. At the moment I just want to know of these events.
So I have created the events and all is working fine, but as soon as I call the event from my GUI app, I receive a message stating: Cross-thread operation not valid ...
So normally I would hook the GUI control to the SynchronizationContext .
For example:
context.Send(new SendOrPostCallback((s) => this.textBox1.Text = "Some Data"), null);
So, my question: how can I develop / alter the event(s) (which runs on a separate thread that the main) to not make use of the above technique, and still be able to send / set data to the GUI controls?
Many thanks in advance.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
Programm3r wrote: So, my question: how can I develop / alter the event(s) (which runs on a separate thread that the main) to not make use of the above technique, and still be able to send / set data to the GUI controls?
If you have to set values to controls that are created by a separate thread, you need techniques like SynchronozationContext , Invoke/BeginInvoke.
BTW, why do you want to do this?
|
|
|
|
|
Thanks for the response Navaneeth.
N a v a n e e t h wrote: BTW, why do you want to do this?
Because, I want to be able to give the user visual confirmation of the following:
New TCP/IP clients that has connectedNew TCP/IP data that has arrivedInform the user when a client has disconnectedUnless you have other suggestions on how this could be achieved?
Thanks again.
Kind regards,
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
hi,
need your help to solve this issue..
i have a custom pictureedit control in which i have many custom properties and events. i need to place an image OVER this in another ordinary picture edit and should be able to work on the events in the picture edit in the lower layer.
i'll make it clearer...
in my custom pictureedit i have added a feature to measure the distance between 2 points. now what i need to do is place another image over the main image and while comparing these images should be able to take the measurements from the lower image...
hope you guys understood my issue clearly...
tons of thanks in advance for any help
|
|
|
|
|
I'm not sure I understood correctly. You have 2 controls, one on top of the other, the covered one is a custom control (you wrote it?) and you want mouse events, I suppose, to pass through to the covered control?
If it's your custom control (you have its code) then you can add methods you can call from the top control mouse event handlers then you make those metods call OnMouse.. methods, raise the events or do what you want to do directly in them. If you don't have the code, I think you can send the appropriate message(s) to the covered control using SendMessage[^].
Eslam Afifi
|
|
|
|
|
Thanks eslam...
i tried using the sendmessage function.. but till now i've not been able to implement it successfully..
so can you help me in this...
actually i make the measurement by dragging through the custom pictureedit(i dont have the source code) which is below the covering control
i tried sending the WM_MOUSEMOVE alone & WM_LBUTTONDOWN & MOUSEMOVE together but nothing much happened...
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam, IntPtr lParam);
private const int WM_MOUSEMOVE = 0x200;
private const int WM_LBUTTONDOWN = 0x201;
private void button2_Click(object sender, EventArgs e)
{
SendMessage(axe.Handle, WM_LBUTTONDOWN, IntPtr.Zero, IntPtr.Zero);
SendMessage(axe.Handle, WM_MOUSEMOVE, IntPtr.Zero, IntPtr.Zero);
}
once again thanks for showing the light..
hope you woulld be able to lead me further
thanks
|
|
|
|
|
What you need is to send a mouse button down message when the mouse is down, mouse move when the mouse is moving and mouse up when the mouse is up. You can experiment to be sure of the message sequence when dragging happens by creating a dummy custom control (or form) with some code similar to the following and figure out the proper message sequence that is generated when you do dragging with it.
protected override void WndProc(ref Message m)
{
Debug.WriteLine(m.ToString());
base.WndProc(ref m);
}
Use this list[^] to facilate analyzing the messages.
Then you can send the appropriate message(s) in the proper event.
By the way, don't send messages with lParam and wParam as IntPtr.Zero since they are supposed to hold modifier keys and mouse coordinates, which you need to make the covered control calculate the distance, otherzise it would calculate zero or some other wrong value since you're notifying it that is the mouse is currently at position (0, 0). See the msdn documentation of WM_LBUTTONDown... to know what to pass to lParam and wParam.
Eslam Afifi
|
|
|
|
|
once again thanks eslam.
i'm still fighting with this.
pls see the log that i got ...
msg=0x201 (WM_LBUTTONDOWN) hwnd=0xb046e wparam=0x0 lparam=0x4b0266 result=0x0
msg=0x7 (WM_SETFOCUS) hwnd=0xb046e wparam=0xd04a4 lparam=0x0 result=0x0
msg=0x8 (WM_KILLFOCUS) hwnd=0xb046e wparam=0x7a045c lparam=0x0 result=0x0
msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x100045c lparam=0x7a045c result=0x0
msg=0xc206 hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0
msg=0x200 (WM_MOUSEMOVE) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0
msg=0x2a1 (WM_MOUSEHOVER) hwnd=0xb046e wparam=0x1 lparam=0xffffffffff5d0230 result=0x0
msg=0x202 (WM_LBUTTONUP) hwnd=0xb046e wparam=0x0 lparam=0xffffffffff5d0230 result=0x0
msg=0x215 (WM_CAPTURECHANGED) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0
msg=0x2a3 (WM_MOUSELEAVE) hwnd=0xb046e wparam=0x0 lparam=0x0 result=0x0
msg=0x111 (WM_COMMAND) hwnd=0xb046e wparam=0x200045c lparam=0x7a045c result=0x0
but nothing special happened...
no event in the message receiving control was fired..
am I missing anything ?
pls help me on this
thanks
|
|
|
|
|
jamesjk wrote: but nothing special happened...
no event in the message receiving control was fired..
am I missing anything ?
The code was not to fire the events. It was to help you find the right message sequence and the lParam and wParam values to pass (read msdn documentation of those messages to find out the correct values to pass). You send the messages using SendMessage.
So I guess the sequence would be sending,
WM_LBUTTONDOWN in mousedown event
WM_MOUSEMOVE in mousemove
WM_MOUSEHOVER in mousehover (just in case the covered control uses it for something, i don't know. the same applies to WM_MOUSELEAVE)
WM_LBUTTONUP in mouseup
I don't know anything about WM_COMMAND nor 0xc206 (I couldn't find anything about it, maybe it's an undocumented message, i don't know). I think you shouldn't use WM_SETFOCUS and WM_KILLFOCUS. WM_CAPTURECHANGED, i don't know, maybe you should send it right after WM_MOUSEUP in mouseup event.
P.S. I've never tried to simulate something like dragging before but I did try sending simple messages before. I don't know much so you should experiment more. And study sequences generated from cases like mousedown, move, leave the control, re-enter the control, move, mouse up... (cases like that) to ensure you get the desired result in both normal cases and extreme cases. And you're welcome.
Eslam Afifi
|
|
|
|
|
Perhaps you could explain again in an other way. It is not clear if you are using 2 controls (one top of other) or are you using 2 images?
|
|
|
|
|
thanks for the reply..
i'll put the problem in another way
i have 2 controls 1. a customized pictureedit 2. a custom picturebox which is transparent
in the customized pictureedit i can measure the distance between 2 points by dragging the mouse from one point to another.
in my form i place the second control exactly over the first one
i load an image in the first control(in which i can take the measurements) that is underneath
then i load different images in the upper transparent picturebox so that i can see both the images overlapping each other..
so far it works fine...
now comes the tricky stuff
i should be able to drag through the upper transparent control and take the difference in measurements between the 2 images. i can't keep the measurable pictureedit on the top as per the requirements.
so what i need to do is drag on the upper transparent picturebox but get measurements as if i dragged on the lower pictureedit.
i hope i have made it clearer this time
once again thanks for the help
|
|
|
|
|
thanks for the reply..
i'll put the problem in another way
i have 2 controls 1. a customized pictureedit 2. a custom picturebox which is transparent
in the customized pictureedit i can measure the distance between 2 points by dragging the mouse from one point to another.
in my form i place the second control exactly over the first one
i load an image in the first control(in which i can take the measurements) that is underneath
then i load different images in the upper transparent picturebox so that i can see both the images overlapping each other..
so far it works fine...
now comes the tricky stuff
i should be able to drag through the upper transparent control and take the difference in measurements between the 2 images. i can't keep the measurable pictureedit on the top as per the requirements.
so what i need to do is drag on the upper transparent picturebox but get measurements as if i dragged on the lower pictureedit.
i hope i have made it clearer this time
once again thanks for the help
|
|
|
|
|
I m trying to add reference of pcrsrv32.dll in c#.NET project(adding reference) but it results error that is
" pcrsrv32.dll can not be added to project make sure its valid assembly or com component"
Plzz help
|
|
|
|
|
I guess pcrsrv32.dll is a native dll. You can add reference to managed assemblies (.net assemblies) but not unmanaged ones. Use DllImport[^] to call unmanaged code.
Eslam Afifi
|
|
|
|
|
Hi all !
i have opened the notepad using the the code as bellow:
System.Diagnostics.ProcessStartInfo obj = new System.Diagnostics.ProcessStartInfo();
obj.FileName = "C:\\Test.txt"
System.Diagnostics.Process objprocess = new System.Diagnostics.Process();
objprocess.StartInfo = obj;
objprocess.Start();
Is it possible to identify whether the notepad(process) is opened through the above code or manually by the user.
I am using WMI(Win32_ProcessStopTrace of Win32ProcessStartTrace)
Pls can some one help me.
thanks in advance
Regards
.....Jack
|
|
|
|
|
I guess you could get the process ID from objprocess? If you loop through all processes running, the one with the ID equal to that of objprocess is the one created by code.
[EDIT]mmm, sorry didn't see the WMI bit, I'm not sure if you can do it then unless you store the info from code somewhere and let WMI look for it there.[/EDIT]
|
|
|
|
|
Thanks for the suggestion.
Now i am storing the information already as you said.But i feel that is not correct. That's fine when u come across any technique then let me know it.
thanks
Regards
.....Jack
|
|
|
|