Home » Eclipse Projects » Eclipse Platform » How to check if UIThread is finnished?
How to check if UIThread is finnished? [message #758431] |
Wed, 23 November 2011 04:34  |
Eclipse User |
|
|
|
Hi,
Another plugin is showing an "operation in progress" and will make my Dialog ( pops up at same time) and Eclipse to hang.
Is it possible to check if the ui thread is still busy and then I can show my Dialog when the thread has finished?
br,
//mike
|
|
| | | |
Re: How to check if UIThread is finnished? [message #758679 is a reply to message #758501] |
Thu, 24 November 2011 03:28   |
Eclipse User |
|
|
|
Hi,
When making the change in CDT it calls the following method:
public IStatus validateEdit(final IFile[] files, final FileModificationValidationContext context) {
if (ClearCasePreferences.isCheckoutAutoNever())
return CANCEL;
final ClearCaseProvider provider = getProvider(files);
final Shell shell = getShell(context);
final boolean askForComment = ClearCasePreferences.isCommentCheckout() && !ClearCasePreferences.isCommentCheckoutNeverOnAuto();
if (null == shell || !askForComment) {
if (PreventCheckoutHelper.isPreventedFromCheckOut(shell, provider, files, ClearCasePreferences.isSilentPrevent())) {
return CANCEL;
}
// UCM checkout.
if (ClearCasePreferences.isUCM() && !ClearCasePreferences.isUseClearDlg()) {
if (!UcmActivity.checkoutWithActivity(provider, files, shell))
// no checkout
return CANCEL;
}
return super.validateEdit(files, context);
}
try {
this.validateEditLock.acquire();
final IFile[] readOnlyFiles = getFilesToCheckout(files);
if (readOnlyFiles.length == 0)
return OK;
final IStatus[] status = new IStatus[1];
PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
public void run() {
status[0] = checkout(readOnlyFiles, shell);
}
});
if (null == status[0])
return CANCEL;
return status[0];
} finally {
this.validateEditLock.release();
}
}
The method I have problem with is:
UcmActivity.checkoutWithActivity(provider, files, shell))
Here is the code for that:
public static boolean checkoutWithActivity(ClearCaseProvider provider, IResource[] resources, Shell shell) {
ShowActivityDialog sad = new ShowActivityDialog(shell, provider, resources);
PlatformUI.getWorkbench().getDisplay().syncExec(sad);
if (sad.isCheckoutAllowed()) {
return true;
} else {
return false;
}
}
And my runnable is:
public class ShowActivityDialog implements Runnable{
private IResource [] resources;
private ClearCaseProvider provider;
private boolean allowCheckout;
private Shell shell;
public ShowActivityDialog(Shell shell, ClearCaseProvider provider, IResource[] resources) {
this.shell = shell;
this.provider = provider;
this.resources = resources;
}
public void run() {
IResource resource = resources[0];
if (resource != null) {
String view = ClearCaseProvider.getViewName(resource);
ActivityDialog dlg = new ActivityDialog(shell, provider, resource);
if (dlg.open() == Window.OK) {
String activity = dlg.getSelectedActivity();
if (activity != null) {
provider.setActivity(activity, view);
allowCheckout = true;
}
} else
// Answer was N or Cancel.
allowCheckout = false;
allowCheckout = true;
}
}
public boolean isCheckoutAllowed() {
return allowCheckout;
}
}
Have I missed anything?
I thought the:
PlatformUI.getWorkbench().getDisplay().syncExec(sad);
made sure that it will run in the UI thread and wait for it to finish.
But when we tested the above code we got "Progress Information" dialog still showing when my Dialog pops up.
br,
//mike
|
|
|
Re: How to check if UIThread is finnished? [message #758963 is a reply to message #758679] |
Fri, 25 November 2011 06:57  |
Eclipse User |
|
|
|
On 2011-11-24 09:28, Mikael Petterson wrote:
> When making the change in CDT it calls the following method:
>
> public IStatus validateEdit(final IFile[] files, final
> FileModificationValidationContext context) {
This function call is not in the UI thread, right?
> if (ClearCasePreferences.isCheckoutAutoNever())
> return CANCEL;
> final ClearCaseProvider provider = getProvider(files);
> final Shell shell = getShell(context);
> final boolean askForComment = ClearCasePreferences.isCommentCheckout()
> && !ClearCasePreferences.isCommentCheckoutNeverOnAuto();
> if (null == shell || !askForComment) {
>
> if (PreventCheckoutHelper.isPreventedFromCheckOut(shell, provider,
> files, ClearCasePreferences.isSilentPrevent())) {
> return CANCEL;
> }
> // UCM checkout.
> if (ClearCasePreferences.isUCM() &&
> !ClearCasePreferences.isUseClearDlg()) {
> if (!UcmActivity.checkoutWithActivity(provider, files, shell))
> // no checkout
> return CANCEL;
> }
>
> return super.validateEdit(files, context);
> }
> try {
> this.validateEditLock.acquire();
> final IFile[] readOnlyFiles = getFilesToCheckout(files);
> if (readOnlyFiles.length == 0)
> return OK;
> final IStatus[] status = new IStatus[1];
> PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
>
> public void run() {
> status[0] = checkout(readOnlyFiles, shell);
> }
> });
> if (null == status[0])
> return CANCEL;
> return status[0];
> } finally {
> this.validateEditLock.release();
> }
> }
>
> The method I have problem with is:
>
> UcmActivity.checkoutWithActivity(provider, files, shell))
>
> Here is the code for that:
>
> public static boolean checkoutWithActivity(ClearCaseProvider provider,
> IResource[] resources, Shell shell) {
>
> ShowActivityDialog sad = new ShowActivityDialog(shell, provider,
> resources);
> PlatformUI.getWorkbench().getDisplay().syncExec(sad);
> if (sad.isCheckoutAllowed()) {
> return true;
>
> } else {
> return false;
> }
> }
>
> And my runnable is:
>
> public class ShowActivityDialog implements Runnable{
>
> private IResource [] resources;
>
> private ClearCaseProvider provider;
>
> private boolean allowCheckout;
>
> private Shell shell;
>
> public ShowActivityDialog(Shell shell, ClearCaseProvider provider,
> IResource[] resources) {
> this.shell = shell;
> this.provider = provider;
> this.resources = resources;
> }
>
> public void run() {
> IResource resource = resources[0];
> if (resource != null) {
> String view = ClearCaseProvider.getViewName(resource);
> ActivityDialog dlg = new ActivityDialog(shell, provider, resource);
> if (dlg.open() == Window.OK) {
> String activity = dlg.getSelectedActivity();
> if (activity != null) {
> provider.setActivity(activity, view);
> allowCheckout = true;
> }
>
> } else
> // Answer was N or Cancel.
> allowCheckout = false;
>
> allowCheckout = true;
> }
>
> }
>
>
>
> public boolean isCheckoutAllowed() {
> return allowCheckout;
> }
> }
>
> Have I missed anything?
>
> I thought the:
>
> PlatformUI.getWorkbench().getDisplay().syncExec(sad);
>
> made sure that it will run in the UI thread and wait for it to finish.
> But when we tested the above code we got "Progress Information" dialog
> still showing when my Dialog pops up.
I think the false assumption is that syncExec will *immediately* enter
the UI thread and perform the task you provided. This is not the case,
the syncExec runnable is also added to the event queue and will be
executed when the queue has been reached this event. This means there is
no guarantee that an other UI event is executed before or after that.
To the contrary, it seems to be intended this way to prevent deadlock
situations. From
http://www.eclipse.org/articles/Article-Concurrency/jobs-api.html
section "Ensuring Data Structure Integrity":
"Another main feature of ILock is the interaction with
Display#syncExec(). If the UI thread is blocked on an ILock#acquire(),
it will still execute syncExecs from other threads that own locks. This
avoids a common deadlock scenario when multiple threads are trying to
update UI."
HTH & Greetings from Bremen,
Daniel Krügler
|
|
|
Goto Forum:
Current Time: Wed Jul 23 14:34:40 EDT 2025
Powered by FUDForum. Page generated in 0.03989 seconds
|