Thread affinity? Try Control.Invoke to get to you click handler.
Just a guess

By on 5/25/2010 9:52 AM ()

Thread affinity? Try Control.Invoke to get to you click handler.

You mean like this:

type M = delegate of string -> unit
let delM = new M (fun x -> MessageBox.Show (x) |> ignore)

let make_icon () =
let n = new NotifyIcon ()
let b = new Bitmap (1, 1)
(Graphics.FromImage (b)).FillRectangle (new SolidBrush(Color.Orange), 0,0,1,1)
n.Icon <- Icon.FromHandle(b.GetHicon ())
n.Click.Add (fun _ -> delM.Invoke("Click"))
n.Visible <- true

It doesn't work either

By on 5/25/2010 10:26 AM ()

Delegate.Invoke is different than Control.Invoke - only the latter will switch threads.
(If that is the problem...)

Eg.:

[link:weblogs.asp.net]

[link:stackoverflow.com]

By on 5/25/2010 10:37 AM ()

Delegate.Invoke is different than Control.Invoke - only the latter will switch threads.
(If that is the problem...)

Eg.:

[link:weblogs.asp.net]

[link:stackoverflow.com]

Such a very amazing link!

__________________
Watch Get Him To The Greek Online Free

By on 6/2/2010 12:47 AM ()

I found the problem. I just forgot Application.Run ()

By on 5/25/2010 10:30 AM ()

Sorry - the GUI thread will be the caller here anyway...

In other cases you may be getting lucky with some APIs, but I tend to route thru Control.Inkoke (or Dispatcher.invoke in WPF) to avoid mysterious behavior - if I change a callback from a click to an event coming from somewhere else, things don't break - been bitten too many time by my code and others'...

By on 5/25/2010 10:46 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper