Hi all,
Hey!
as I know Gtk# is not thread-safe (is it planned to be?).
As far as I know, no. This is going to add great overhead and there Application.Invoke() is easy enough to use that I can't even call it a workaround (maybe "design decision" =) ).
I guess it is the reason of my errors,I have an application (1) which starts a separate thread (2) when some task starts and that task makes callsto custom dll using pinvoke. Is it safe to attach to events of (2) in (1) and to send results to some Widget whenthey are invoked?
No. Do some kind of "shielding" that uses Application.Invoke. For example, instead of:
Thread1.SomeEvent += Thread2.SomeCallback;
Try:
Thread1.SomeEvent += delegate (Object myarg) {
Gtk.Application.Invoke(delegate {
Thread2.SomeCallback(myarg);
});
};
You could even create a shielding function, like:
public MyDelegate ApplicationInvoke(MyDelegate callback) {
return delegate (Object myarg) {
Gtk.Application.Invoke(delegate {
Thread2.SomeCallback(myarg);
});
};
}
And use like:
Thread1.SomeEvent += ApplicationInvoke(Thread2.SomeCallback);
Another thing is a little bit offtop but ... when I kill a child thread with Thread.Abort() the next time I start itit can't make calls to the underlying C++ dll anymore :((, probably someone experienced this kind of problem?
Try Thread.Interrupt(); or use something to stop inside of your code (better), i.e.:
public void ThisFunctionIsExecutedOnAnotherThread() {
stop = false;
while (!stop) {
DoSomething();
}
}
public void Stop() {
stop = true;
}
I also saw some attrbutes which can make my calls to the dll library more safe (in case they damage some memory)?Because when I exit my application I usually get something like Debug Error: DAMAGE: before Normal block (#-134134241) at 0x054532344
Well... this I don't know =D!
Thanks in advance,
You're welcome!
--Gena
Cheers,
Felipe.
--
"Quem excele em empregar a força militar subjulga os exércitos dos outros
povos sem travar batalha, toma cidades fortificadas dos outros povos sem as
atacar e destrói os estados dos outros povos sem lutas prolongadas. Deve
lutar sob o Céu com o propósito primordial da 'preservação'. Desse modo suas
armas não se embotarão, e os ganhos poderão ser preservados. Essa é a
estratégia para planejar ofensivas."
-- Sun Tzu, em "A arte da guerra"
_______________________________________________ Gtk-sharp-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
