Home » Eclipse Projects » Standard Widget Toolkit (SWT) » blocking while creating embeded native window for SWT control
| blocking while creating embeded native window for SWT control [message #409984] |
Thu, 15 January 2004 02:49  |
Eclipse User |
|
|
|
Originally posted by: jfzhang.usa.net
Hi,
Anyone here can give suggesting in this problem? many thanks.
We are now developing a new swt control to embed a native window on win32
platform, it looks like:
public mySWTControl extends Composite {
NativeWindow mywin;
public mySWTControl (Composite parent, int style) {
super(parent, style);
mywin = createNativeWindow(parent);
...
//Some other process, need mywin has been created.
...
}
...
}
public class Toolkit {
...
public NativeWindow createNativeWindow(Composite parent){
return asyncCreateNativeWindow(parent);
}
...
private NativeWindow asyncCreateNativeWindow() {
// create the native window by sending a message to a queue, and
// wait for response to send back the window handle.
...
}
}
The API createNativeWindow() will asynchroniously call win32 API
CreateWindowExW() remotely to create the native window. My problem is,
when the native window's parent is the SWT one, win32 api createWindowExw
will block forever; if change the parent to a Desktop or some other non-
swt window, the blocking will go away. Here are the methods I tried:
1. creat the window in a seperate java thread,
public mySWTControl (Composite parent, int style) {
super(parent, style);
new Thread( new Runnable() {
public void run() {
mywin = createNativeWindow(parent);
}
}).start();
try {Thread.sleep(1000)} catch{...}
...
}
It works for most times, but sometimes it blocks on win32 api
createWindowExw() too.
2. By using UI thread async/sync method,
public mySWTControl (Composite parent, int style) {
super(parent, style);
Display.getCurrent.async( new Runnable() {
public void run() {
mywin = createNativeWindow(parent);
}
}
...
}
The result is not blocking.
It looks while creating the native window, it requires the main process
has released some mysterious system resource, and also it is required to
finish creating the windows before other code can be executed, anyone can
suggest what I can do the problem?
zhangjf
|
|
|
| Re: blocking while creating embeded native window for SWT control [message #410244 is a reply to message #409984] |
Thu, 15 January 2004 12:39   |
Eclipse User |
|
|
|
Wow. This is a pretty Widnows specific question that doesn't have much to do
with SWT. You know that Windows is appartment threaded so if you are
actually creating a window in another thead, you will need an event loop in
that thread to feed it, right? The SWT event loop (just like every other
Windows event loop) will never dispatch events to widgets that are created
in other threads.
If you are really playing the thread game, try doing the same kind of thing
with two SWT Displays (unofficially supported on Windows) and just create
normal SWT controls. All we are doing is eventually calling
CreateWindowEx() to create controls, just like your native does. Debug the
interactions without calling any C code, using Eclipse to see which threads
are hung and where. If this works, find out what your control is doing that
is different. For example, if it is calling SendMessage() to the parent, it
could be causing deadlock because you sending a Windows message across
threads.
Good luck!
"jfzhang" <jfzhang@usa.net> wrote in message
news:Xns9471A149682E2jfzhang@204.138.98.10...
> Hi,
>
> Anyone here can give suggesting in this problem? many thanks.
>
> We are now developing a new swt control to embed a native window on win32
> platform, it looks like:
>
> public mySWTControl extends Composite {
> NativeWindow mywin;
> public mySWTControl (Composite parent, int style) {
> super(parent, style);
> mywin = createNativeWindow(parent);
> ...
> //Some other process, need mywin has been created.
> ...
> }
> ...
> }
>
> public class Toolkit {
> ...
> public NativeWindow createNativeWindow(Composite parent){
> return asyncCreateNativeWindow(parent);
> }
> ...
> private NativeWindow asyncCreateNativeWindow() {
> // create the native window by sending a message to a queue, and
> // wait for response to send back the window handle.
> ...
> }
> }
>
>
>
>
> The API createNativeWindow() will asynchroniously call win32 API
> CreateWindowExW() remotely to create the native window. My problem is,
> when the native window's parent is the SWT one, win32 api createWindowExw
> will block forever; if change the parent to a Desktop or some other non-
> swt window, the blocking will go away. Here are the methods I tried:
>
>
> 1. creat the window in a seperate java thread,
>
> public mySWTControl (Composite parent, int style) {
> super(parent, style);
> new Thread( new Runnable() {
> public void run() {
> mywin = createNativeWindow(parent);
> }
> }).start();
>
> try {Thread.sleep(1000)} catch{...}
> ...
> }
>
>
> It works for most times, but sometimes it blocks on win32 api
> createWindowExw() too.
>
> 2. By using UI thread async/sync method,
>
> public mySWTControl (Composite parent, int style) {
> super(parent, style);
> Display.getCurrent.async( new Runnable() {
> public void run() {
> mywin = createNativeWindow(parent);
> }
> }
> ...
> }
>
> The result is not blocking.
>
> It looks while creating the native window, it requires the main process
> has released some mysterious system resource, and also it is required to
> finish creating the windows before other code can be executed, anyone can
> suggest what I can do the problem?
>
>
> zhangjf
|
|
|
| Re: blocking while creating embeded native window for SWT control [message #410245 is a reply to message #409984] |
Thu, 15 January 2004 12:42  |
Eclipse User |
|
|
|
It could be that I've misunderstood what you're trying to do, but an
asynchronous call won't block - what you want is synchronous execution.
In method 2 try:
Display.getCurrent.syncExec(....
Cheers,
Alun
jfzhang wrote:
> Hi,
> Anyone here can give suggesting in this problem? many thanks.
> We are now developing a new swt control to embed a native window on win32
> platform, it looks like:
> public mySWTControl extends Composite {
> NativeWindow mywin;
> public mySWTControl (Composite parent, int style) {
> super(parent, style);
> mywin = createNativeWindow(parent);
> ...
> //Some other process, need mywin has been created.
> ...
> }
> ...
> }
> public class Toolkit {
> ...
> public NativeWindow createNativeWindow(Composite parent){
> return asyncCreateNativeWindow(parent);
> }
> ...
> private NativeWindow asyncCreateNativeWindow() {
> // create the native window by sending a message to a queue, and
> // wait for response to send back the window handle.
> ...
> }
> }
> The API createNativeWindow() will asynchroniously call win32 API
> CreateWindowExW() remotely to create the native window. My problem is,
> when the native window's parent is the SWT one, win32 api createWindowExw
> will block forever; if change the parent to a Desktop or some other non-
> swt window, the blocking will go away. Here are the methods I tried:
> 1. creat the window in a seperate java thread,
> public mySWTControl (Composite parent, int style) {
> super(parent, style);
> new Thread( new Runnable() {
> public void run() {
> mywin = createNativeWindow(parent);
> }
> }).start();
> try {Thread.sleep(1000)} catch{...}
> ...
> }
> It works for most times, but sometimes it blocks on win32 api
> createWindowExw() too.
> 2. By using UI thread async/sync method,
> public mySWTControl (Composite parent, int style) {
> super(parent, style);
> Display.getCurrent.async( new Runnable() {
> public void run() {
> mywin = createNativeWindow(parent);
> }
> }
> ...
> }
> The result is not blocking.
> It looks while creating the native window, it requires the main process
> has released some mysterious system resource, and also it is required to
> finish creating the windows before other code can be executed, anyone can
> suggest what I can do the problem?
> zhangjf
|
|
|
Goto Forum:
Current Time: Wed Nov 05 14:38:01 EST 2025
Powered by FUDForum. Page generated in 0.04440 seconds
|