Re: [Asterisk-java-users] The asteriks-java event can't use in SWT?
Brought to you by:
srt
From: Stefan R. <sr...@re...> - 2005-07-12 10:36:06
|
Hi, what you got when running your application is probably an SWTException telling you about an invalid thread access. This is neither an Asterisk-Java problem not an SWT problem. Regardless of using either Swing or SWT you are not allowed to access the GUI from another Thread than the one that created the GUI, because neithe= r Swing nur SWT widgets are thread safe. The difference is that SWT actuall= y enforces this and prevents you from doing something that is not thread safe, while Swing doesn't resulting in people having unpredictable bugs i= n their applications. Your handleEvent() is invoked by Asterisk-Java's event handling thread an= d must therefore not access any widgets directly. The solution to your problem is to use the asyncExec() method of Display: [...] public void handleEvent(ManagerEvent event) { if ( (event instanceof DialEvent)) { DialEvent dial =3D (DialEvent) event; final List list =3D eventList; final String text =3D "Caller ID:" + dial.getCallerId(); eventList.getDisplay().asyncExec(new Runnable() { public void run() { list.add(text); } }); } } [...] Note that the variables you want to access within the inner class must be declared final. Hope that helps =3DStefan |