Click here to Skip to main content
15,890,527 members
Home / Discussions / C#
   

C#

 
AnswerRe: Converting a relative path into an absolute one Pin
Curtis Schlak.14-Nov-05 4:55
Curtis Schlak.14-Nov-05 4:55 
GeneralRe: Converting a relative path into an absolute one Pin
Dan Neely14-Nov-05 5:19
Dan Neely14-Nov-05 5:19 
GeneralRe: Converting a relative path into an absolute one Pin
Curtis Schlak.14-Nov-05 5:30
Curtis Schlak.14-Nov-05 5:30 
QuestionCustom control that can contain other controls Pin
Christian Wikander14-Nov-05 3:04
Christian Wikander14-Nov-05 3:04 
AnswerRe: Custom control that can contain other controls Pin
Gulfraz Khan14-Nov-05 5:04
Gulfraz Khan14-Nov-05 5:04 
QuestionFire events without BeginInvoke? Pin
Russell Jones14-Nov-05 3:03
Russell Jones14-Nov-05 3:03 
AnswerRe: Fire events without BeginInvoke? Pin
S. Senthil Kumar14-Nov-05 4:45
S. Senthil Kumar14-Nov-05 4:45 
AnswerRe: Fire events without BeginInvoke? Pin
Frederic Vaillancourt14-Nov-05 10:32
Frederic Vaillancourt14-Nov-05 10:32 
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 />
   //And for every delegate signature you want to support, usually just a few<br />
   //Example for a   void ( object, EventArgs ) handler<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 />
//And use it this way<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.
QuestionMessagebox with YestToAll, NoToAll Pin
abcxyz8214-Nov-05 1:59
abcxyz8214-Nov-05 1:59 
AnswerRe: Messagebox with YestToAll, NoToAll Pin
Dan Neely14-Nov-05 2:04
Dan Neely14-Nov-05 2:04 
QuestionProblem with devenv in VS.Net 2005. Plz Help!!! Pin
Dhivya Natarajan14-Nov-05 1:19
Dhivya Natarajan14-Nov-05 1:19 
QuestionRegarding Toolbar Pin
A.Grover14-Nov-05 0:35
A.Grover14-Nov-05 0:35 
QuestionDateTimePicker With multi selection Pin
charbelasmar14-Nov-05 0:31
charbelasmar14-Nov-05 0:31 
QuestionActive Directory Problem Pin
Hamzeh14-Nov-05 0:20
Hamzeh14-Nov-05 0:20 
Questionapp.config not visible Pin
sandeep_programmer13-Nov-05 23:54
sandeep_programmer13-Nov-05 23:54 
AnswerRe: app.config not visible Pin
Sean Michael Murphy14-Nov-05 5:18
Sean Michael Murphy14-Nov-05 5:18 
QuestionReturning an array from a web service Pin
Kaliku13-Nov-05 22:57
Kaliku13-Nov-05 22:57 
QuestionMonday in actual Calendar Week Pin
mimei13-Nov-05 22:37
mimei13-Nov-05 22:37 
Questioni wanna my application apprear with slow motion Pin
malak nour13-Nov-05 22:16
malak nour13-Nov-05 22:16 
AnswerRe: i wanna my application apprear with slow motion Pin
mav.northwind14-Nov-05 1:29
mav.northwind14-Nov-05 1:29 
AnswerRe: i wanna my application apprear with slow motion Pin
Mike Dimmick14-Nov-05 2:37
Mike Dimmick14-Nov-05 2:37 
GeneralRe: i wanna my application apprear with slow motion Pin
Dan Neely14-Nov-05 4:21
Dan Neely14-Nov-05 4:21 
AnswerRe: i wanna my application apprear with slow motion Pin
S. Senthil Kumar14-Nov-05 2:38
S. Senthil Kumar14-Nov-05 2:38 
Questionconverting hex value to unicode character Pin
Meysam Mahfouzi13-Nov-05 20:51
Meysam Mahfouzi13-Nov-05 20:51 
AnswerRe: converting hex value to unicode character Pin
wheelerbarry13-Nov-05 21:31
wheelerbarry13-Nov-05 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.