|
Must remember the other execution is stuff not within the thread that the waitone was called on or other processes running on the system.
|
|
|
|
|
Thanks Spacix,
Spacix One wrote: Must remember the other execution is stuff not within the thread that the waitone was called on or other processes running on the system.
Could you describe your above points in some other words please? Sorry my English is not very good and I am very interested to learn from your points.
regards,
George
|
|
|
|
|
Thanks N a v a n e e t h,
N a v a n e e t h wrote: But WaitHandle.WaitOne() allows you to do some processing before EndInvoke() is called
I agree all of your points and they are great! Except the above one, I think EndInvoke can achieve the same effect, e.g. you can do something and then invoke EndInvoke.
So, I think the approach of using EndInvoke and the approach of using WaitHandle are the same (at least from functional and effective perspective)?
regards,
George
|
|
|
|
|
George_George wrote: I think EndInvoke can achieve the same effect, e.g. you can do something and then invoke EndInvoke.
It not same fully even though it looks same. When you use WaitOne() , you are allowed to do some extra processing before EndInvoke() is called. That is WaitOne() will wait until the asynchronous method signals it, then the code will come to the next line where you can do further processing and call EndInvoke(). But if you call EndInvoke() directly, it blocks the current thread until it returns the result. Hence you won't be able to do any further processing outside the asynchronous method.
Hope it's clear.
|
|
|
|
|
Thanks N a v a n e e t h,
I want to confirm with you that we can call EndInvoke even if after the asynchronous method completes to retrieve results, right (in this case, EndInvoke will return immediately)?
regards,
George
|
|
|
|
|
George_George wrote: we can call EndInvoke even if after the asynchronous method completes to retrieve results, right
I am sorry, but I am not getting you. Can you rephrase your question ?
George_George wrote: N a v a n e e t h,
There is no space in my name. It's Navaneeth. I added space simply
|
|
|
|
|
Thanks Navaneeth,
Sorry for my bad English.
My question is, if we call EndInvoke after the completion of the asynchronous method, EndInvoke will not be blocked and we will get return result from EndInvoke (or exception) without blocking, right?
regards,
George
|
|
|
|
|
Yes. It will be returned immediately.
|
|
|
|
|
Thanks N a v a n e e t h,
Question answered.
regards,
George
|
|
|
|
|
It's recommended that you call EndInvoke for every BeginInvoke called, regardless of whether you wait for completion. The MSDN page (http://msdn2.microsoft.com/en-us/library/2e08f6yc.aspx[^]) clearly says "Always call EndInvoke to complete your asynchronous call.".
1. Any exceptions that occurred in the asynchronous method will be thrown when you call EndInvoke, so if you don't call it, you'll miss those.
2. If the async method has any return values or out/ref parameters, then you'll need to obviously call EndInvoke to get them.
|
|
|
|
|
Good point, Senthil!
Two more comments,
1.
From the link you referred, I can not find words like "Always call EndInvoke to complete your asynchronous call", and it is appreciated if you could point out.
2.
S. Senthil Kumar wrote: 1. Any exceptions that occurred in the asynchronous method will be thrown when you call EndInvoke, so if you don't call it, you'll miss those.
I think you mean some code only calls WaitHandle without calling EndInvoke (WaitHandle is singnalled when asynchronous call completes, and you can have choice to ignore return value by without calling EndInvoke)?
If yes, I think the asynchronous method should be executed in another CLR thread, other than the current thread. Right?
And if any exception occurs in the CLR thread, could be caught in the current thread? I doubt it. Since I think the C# exception handling approach does not allow us to have cross-threads exception handling -- means exception occurs in one thread, and we can catch it in another thread? Any comments?
regards,
George
|
|
|
|
|
George_George wrote: From the link you referred, I can not find words like
Really? Did you try searching for the text? It's there in a small rectangular area titled "Important note".
George_George wrote: If yes, I think the asynchronous method should be executed in another CLR thread, other than the current thread. Right?
Um, but isn't that the very definition of an asynchronous method?
George_George wrote: And if any exception occurs in the CLR thread, could be caught in the current thread? I doubt it. Since I think the C# exception handling approach does not allow us to have cross-threads exception handling -- means exception occurs in one thread, and we can catch it in another thread? Any comments?
Any exceptions that occurred in the asynchronous method will be caught by the .NET framework and will be rethrown in the thread that calls EndInvoke. So yes, the framework does have the ability to handle exceptions across threads.
|
|
|
|
|
Cool, Senthil!
S. Senthil Kumar wrote: Any exceptions that occurred in the asynchronous method will be caught by the .NET framework and will be rethrown in the thread that calls EndInvoke. So yes, the framework does have the ability to handle exceptions across threads.
I think .Net framework does something special here in asynchronous method call. In normal case of multi-threaded programming in C#, the exception thrown from one thread can not be caught from another thread, right?
regards,
George
|
|
|
|
|
George_George wrote: In normal case of multi-threaded programming in C#, the exception thrown from one thread can not be caught from another thread, right?
Yes, because each thread has its own stack and exceptions cannot be propagated across stacks.
|
|
|
|
|
Thanks Senthil,
Your answer is clear.
regards,
George
|
|
|
|
|
hi all
i recently develop a project about E-seal(with office2007 word document), now i get the word file hash value(digest), and i need to put it back to the document, but i donot know which position of document is perfect. it is about the office program, so i use VSTO.
can anybody give prompt in detail
appreciate for any reply
|
|
|
|
|
Hi,
I am developing application in asp.net 2.0 using C#. My back end is sql server 2005. I also use microsoft enterprise library 2006.
My problem is:
First i pass three parameters to stored procedure from the application. After i increase one more parameter in both application as well as stored procedure, the application gives an error that parameter does not match with the stored procedures parameters.
after couple of hours when i restart the machine and again run the application it works fine with four parameters.
does sql server 2005 stores the parameters in cache??
if it does not keep it in cache then how come i get an error that values does not match the values in the stored procedure??
modified on Monday, April 28, 2008 10:30 AM
|
|
|
|
|
what is the equivalent of following C structure in c#
struct mystructure
{
int number;
char name[256];
};
Rajesh
|
|
|
|
|
Hi,
it depends on what you want it for. If it's just data being shared between two
pieces of C# code, then use:
struct myStructure {
int number;
string name;
}
and it will hold your data, whatever the length of the name string will be.
If on the other hand you want to share the data with code in another programming language,
or with a hardware device, then it will take more effort (e.g.with Marshaling attributes
or code) to match the requirements.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
actually i am writing some fields from webpages to file
using structure. then I read the file using same structure
in the c++ programme . in c++ no string data type so I cannot use string
in my structure
Rajesh
|
|
|
|
|
|
I am c# programmer and c++ site cannot change .it is already running and cannot change huge code there.
Rajesh
|
|
|
|
|
Fair enough then.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Three comments then:
so it is a binary file (because of the int) although probably most of the data is text?
I would make it all text then (hence use int.ToString and/or int.TryParse)
are you aware of character sizes? in C/C++ it could be 8-bit or 16-bit, on C# it will
be 16-bit.
Some people would recommend using XML for something like this. I'm still undecided.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
You can use a BinaryWriter to write the data to the file.
The .NET equivalent of a C++ char is a byte. If you have text to put in the file, you have to know what encoding to use to turn it into an array of bytes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|