|
Hi all,
I'm writing an assembly which processes incoming messages from a tcp socket and fires an event if a relevant message is received. I understand the need to fire the message on the appropriate thread, but was hoping that instead of the consumer of my client having to use begininvoke, i could somehow pass in the thread I want the event to fire on as a parameter and have the control handle the event without 'knowing' which thread it came from.
Is this at all possible, or have i missed what is going on here.
Thanks for any help anyone gan give,
Russell
|
|
|
|
|
|
arachnoid wrote: understand the need to fire the message on the appropriate thread
Does that come from the need of modifying the UI on the thread it was created? You usually only have one UI thread so writing formname.BegingInvoke isn't too complicated.
If you are talking about worker threads that only process the events without touching the UI, I usually just queue them in a work queue. I wrote a class that create a delegate that do it transparently from another one. I really should write an article on that.
You can mix both technique to have both UI and direct delegate on the same event, just make a class like this:
class UIDelegate<br />
{<br />
private ISynchronizeInvoke mSync;<br />
private Delegate mDelegate;<br />
<br />
public static Delegate Create( ISynchronizeInvoke sync, Delegate d )<br />
{<br />
UIDelegate newd = new UIDelegate( sync, d );<br />
return Delegate.CreateDelegate( d.GetType(), newd , "Handler" );<br />
}<br />
<br />
private UIDelegate( ISynchronizeInvoke sync, Delegate d )<br />
{<br />
mSync = sync;<br />
mDelegate = d;<br />
}<br />
<br />
private void Handler( object sender, EventArgs arg )<br />
{<br />
if ( mSync.InvokeRequired )<br />
{<br />
mSync.BeginInvoke( mDelegate, new object[]{ arg } );<br />
}<br />
else<br />
{<br />
mDelegate.DynamicInvoke( new object[]{ arg } );<br />
}<br />
}<br />
}<br />
<br />
myObjectOnAnotherThread.AnEvent += (EventHandler)UIDelegate.Create( theForm, new EventHandler(TheFunction) );
I am trying to get the indentation right but it seems I cant figure it out and I need to go home.
I did not compile it, just wrote what I remember from the class I have at home.
That will hide the ugly forwarding into the UIDelegate class this was other classes do not need to be aware of UI things to do their job correctly.
I use the same principle to queue the request and execute it later on my worker threads.
|
|
|
|
|
I need to implement YesToAll,NoToAll feature with messagebox. Say I have several images, when user selects ClearAll...I want to show Prompt with Yes,No,YesToall,NoToAll..Yes would delete current image and prompt with next image, No would skip current image and prompt with next image
How can it communicate with business logic? I have to pop up messagebox each time if user selects yes or no for image
Thanks for anticipation.
Regards,
MaulikCE
|
|
|
|
|
You need to a create a form with that functionality. Messagebox doesn't provide any way to do it.
|
|
|
|
|
Hi Everyone,
I went through a article "Build solution from command line or with contexmenu item with Microsoft VS.NET" and i tried the code in VS.Net 2003"
Link: www.codeproject.com/dotnet/builditemincontextmenu.asp
written by "Jerry Maguire".
Using that application i tried to create dll for a solution file created in VS.Net2003, Its working fine.
But when tried it for a solution file written in VS 2005, it raises error.
Should i change anything from that given code?
Plz help me to solve this issue.
Thanks & Regards,
Dhivya N.
-- modified at 7:20 Monday 14th November, 2005
|
|
|
|
|
i am working with c# windows control library. i have made a toolbar. in toolbar i have one text field. i want when i type a name of website it will open in the Same IE like Address Bar in IE
Amit Grover
CDAC R&D
Gist Group
pune
|
|
|
|
|
hi
I'm working on DateTimePicker with multi selection like you can choose
12 nov. ,14 nov. and 15 nov. on the same time by clicking them
so if anyone can help or have source code
best regards
charbel
|
|
|
|
|
I am creating an application that access the active direcotry to add new users, it works fine but after some time and while the application is still running, i get this error message:
An unhandled exception of type 'System.NullReferenceException' occurred in system.directoryservices.dll
Additional information: Object reference not set to an instance of an object.
And in the disassembly window, i find System.DirectoryServices.SearchResultCollection.Dispose in the address.
What is the problem with using the searchresultcollection although i enforce the dispose method after i finish using it, i tried to analyze whats going on but no use till now. Any help, any ideas plz it's very critical for me...
|
|
|
|
|
hi experts,
i am not able to include app.conig in my windows application. It is not visible in project-->Add Item--> New items. Plz help
with regards,
sandeep yadav
|
|
|
|
|
sandeep_programmer wrote: i am not able to include app.conig in my windows application. It is not visible in project-->Add Item--> New items. Plz help
I can't imagine why it wouldn't be visible, but to get around the problem just add a new text file, call it App.config , and add the following text to it:
="1.0"="utf-8"
<configuration>
</configuration> It will behave the correct way. There's nothing special about App.config when it's being edited.
Share and enjoy.
Sean
|
|
|
|
|
I am trying to return an array from a web service method that is accessed by an external application, and I get Error 500 - Internal server error
How can it be done?
|
|
|
|
|
Hi
how can I get the Date of the Monday in the actual or the next Calendar Week?
for example, next week is week Nr 47 and I want to know which Date is at Monday in this week.
Thanks a lot for help
Greets
|
|
|
|
|
i'm working in application that have alot of forms appear so i wanaa some of those forms appear by another way from the others form so can any one help me tell me wat can i do to let my form appear in slow motion
|
|
|
|
|
I think I speak for all of us when I say "huh?"
Could you please describe your requirements in more detail?
mav
|
|
|
|
|
Do you mean the animation that occurs when you minimise or restore an application? You can ask Windows to draw that animation for you using the DrawAnimatedRects function.
For a C# example, see here[^].
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Until you mentioned this I never noticed it happening. Is it like the bouncing cards in win3.1/9x solitaire that lacked any sort of execution delay which looked good on the slow machines when written but broke itself on faster processors?
|
|
|
|
|
|
I couldn't find the corresponding method in msdn. would you help me? I've got a hex value like 0x0E03(stored as an int variable) and want to convert it to its corresponding unicode character.
|
|
|
|
|
Use the Convert.ToChar method in the Convert class, with the int that you have.
|
|
|
|
|
Hello; because of some problems(money) with company they didnt send me dll file for reading information from RFID kit. Is it possible to read information from RFID kit with a regular serial port programs
i use .net 2003 and framework 1.1
ubt i think i have to install framework 2.0
can you help please
thanks
|
|
|
|
|
I found answer.
if we assign 38400 baud rate and suitable com port number in the code, it is possible . but in just .net framework 2.0
|
|
|
|
|
hi
i want to execute my module which is saved in text file on local drive. module looks like
========================================================
Public Sub DynamicModule () as String
Return "Module Loaded"
End Sub
========================================================
the above module is just a sample, in actual i want to perform extra tasks
quick replies are highly appreciated
AMJ (With "Z" Factor)
|
|
|
|
|
How to Download a file from a remote FTP server.what is the process and code for it.
-- modified at 0:13 Monday 14th November, 2005
|
|
|
|
|
What type of server? Microsoft File Server, Novell, FTP, WEB, TFTP, Linux, Samba, ..., ..., ..., ?
The completeness and quality of answer you get lies in the details of the question you ask.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|