|
Bob_Sun wrote: BeginInvoke and EndInvoke should be called in pair,
Hmm, I don't believe that is correct (but could be wrong). See this[^] MSDN article.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Of cause, I haven't found any such discription in MSDN articles, just on some forum. But the fact is that my program do stop at somethere in the invoked thread (maybe for some other reasons).
As the detail of ThreadPool is not opened completely, now I am considering of writing a ThreadManager of my own, just start a thread by Thread.Start(), if necessary cancel it by Thread.Abort().
|
|
|
|
|
|
Rest assured. EndInvoke is ONLYused if your asyncronous method returns something. You call EndInvoke to retrieve that return value, since you can't get the return value in any other way. EndInvoke does not do anything else apart from giving you the return value. If you are not interested in the return value, you do not need to call EndInvoke. I have used BeginInvoke so many times in so many performance critical applications without using EndInvoke, it doesn't create a problem
|
|
|
|
|
Tehnoon wrote: I have used BeginInvoke so many times in so many performance critical applications without using EndInvoke, it doesn't create a problem
Thank you for quick reply.
In my case, this is the opposite, it seems to me that the thread invoked by BeginInvoke disappeared half way(only part of the log left). I am not sure whether a background thread will disappear half way if GC.Collect() happens during its process? I am investigating for the reason...
Thank you
|
|
|
|
|
delegate.BeginInvoke (creates new thread [from thread-pool]) without delegate.EndInvoke will cause a memory leak.
Control.BeginInvoke ('sends' call to main thread) without Control.EndInvoke is no problem.
|
|
|
|
|
Daniel Grunwald wrote: delegate.BeginInvoke (creates new thread [from thread-pool]) without delegate.EndInvoke will cause a memory leak.
I am troubled by threads invoked from ThreadPool.
Can you give me some hint about what the memory leak will bring about?
Thank you.
|
|
|
|
|
I think you will leak one WaitHandle for each delegate.BeginInvoke call, plus any objects waiting to be returned (e.g. exceptions). When you want to use the thread-pool in "fire-and-forget" mode, use hreadPool.QueueUserWorkItem or provide a callback-method to delegate.BeginInvoke that in turn calls delegate.EndInvoke.
|
|
|
|
|
Can you show the code in which you are invoking the thread which is creating the problem? Garbage collection will not be done unless the thread is finished with the execution. The only possibility that I am seeing here is that the system is not being able to provide all the requested resources by the program and hence the results are not coming out as expected. A look at the source code will give me a better idea of this.
|
|
|
|
|
Tehnoon wrote: Can you show the code in which you are invoking the thread which is creating the problem? Garbage collection will not be done unless the thread is finished with the execution. The only possibility that I am seeing here is that the system is not being able to provide all the requested resources by the program and hence the results are not coming out as expected. A look at the source code will give me a better idea of this.
Sorry for a late response.
A statemachine exists in my program, and all the events are dispatched to it by seperate threads.The code is something like the following.
public class Control
{
private StateMachine myStateMachine = new StateMachine();
public void EventProc1()
{
....
EventHandler eventHandler = new EventHandler(this.Thread1);
eventHandler.BeginInvoke(this,null,null,null);
}
public void EventProc2()
{
....
EventHandler eventHandler = new EventHandler(this.Thread2);
eventHandler.BeginInvoke(this,null,null,null);
}
protected void Thread1(object sender,EventArgs e)
{
LogMessage("Start of thread1");
this.myStateMachine.Dispatch(1);
}
protected void Thread2(object sender,EventArgs e)
{
LogMessage("Start of thread2");
this.myStateMachine.Dispatch(2);
}
}
public class StateMachine
{
public void Dispatch(event id)
{
switch(event id)
{
case 1:
....
break;
case 2:
....
break;
...
default:
break;
}
}
}
Up to now, many phenomena happened, such as although the LogMessage were logged in log file, the thread just stopped somewhere afterward. Or sometimes, one thread should be waiting for an AutoResetEvent which must be set in another thread as designed, but the previous thread moves on before the AutoResetEvent is Set()...
Another important supplement is that GC.Collect() is executed in another thread, ie. in EventProc1().
I have written many test programs so as to find the real reason, and still don know where a memory leak brought by no-EndInvoke will lead to the above phenomena.
Looking forword to your help.
Thank you!
|
|
|
|
|
can any body tell me about something about Encoding class
|
|
|
|
|
Such as? We'll need a bit more clarifcation about what you want. You've just asked a question like "Can someone tell me something about a car?"
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
|
In waht aspect do you want to know about Encoding?
Regards.
|
|
|
|
|
Is there a easy way to remove the black border around a Forms.Button when it is set to a FlatStyle of Flat? The button has a bitmap image on it and there doesn't seem to be a way to get rid of the black border around the button when it is selected or not selected.
I would think there would be a property to set it on or off but I don't see any. Does anyone know?
|
|
|
|
|
Set its FlatAppearance.BorderSize to 0.
--
I've killed again, haven't I?
|
|
|
|
|
you may change the forecolor to your interface color.
this.button3.ForeColor = System.Drawing.SystemColors.Control;
|
|
|
|
|
Hi everyone!
I have a webpage that allows a user to upload a file for storage in a database. However, I am having a problem when users try to upload a bigger file (usually 3MB+). I am assuming that this is because I am trying to send the entire file to the server at once How can I get around this?
Any help is greatly appreciated
|
|
|
|
|
could it be that since the file is so large/connection is so slow, the operation times out?
as to get around it, you could have the file rar'ed (like a zip) which will zip it up into pieces and then send the pieces bit by bit. Also, try compressing the file so that it gets smaller.
If not, use FTP connection instead of form based.
|
|
|
|
|
jeweladdict wrote: could it be that since the file is so large/connection is so slow, the operation times out?
I am assuming so.
Adding a rar or zip to the file might help but it is not something that i really want to do. Is there a way that you know of that I can send the file to the server in pieces?
Thanks
|
|
|
|
|
ftping would be the best bet.
|
|
|
|
|
Ok thanks i'll give that a try
I also have a another question... Is it better to save the file to a database on the server or right on the disk?
|
|
|
|
|
That depends on how you are going to use the file.
---
b { font-weight: normal; }
|
|
|
|
|
There's a limit on the size of a request, I believe it's 4 MiB by default. Could it be that? Then you can change the limit in web.config.
---
b { font-weight: normal; }
|
|
|
|
|
Thats news to me How would I make those changes?
Thanks
|
|
|
|