Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 09:34 Go to next message
Mikael Petterson is currently offline Mikael Petterson
Messages: 152
Registered: July 2009
Senior Member
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 #758467 is a reply to message #758431] Wed, 23 November 2011 11:44 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 2011-11-23 10:34, Mikael Petterson wrote:
> Another plugin is showing an "operation in progress" and will make my
> Dialog ( pops up at same time) and Eclipse to hang.

Please describe your scenario properly: It is far from clear, what you
are trying to do. Are you using the Job API, are you using one of the
Display.*Exec functions? You are aware that using, for example
Display.syncExec is very sensitive to dead lock situations, aren't you?

> Is it possible to check if the ui thread is still busy and then I can
> show my Dialog when the thread has finished?

Just use Display.asyncExec when your non-UI work has finished.

HTH & Greetings from Bremen,

Daniel Krügler
Re: How to check if UIThread is finnished? [message #758479 is a reply to message #758467] Wed, 23 November 2011 12:22 Go to previous messageGo to next message
Mikael Petterson is currently offline Mikael Petterson
Messages: 152
Registered: July 2009
Senior Member
Hi,

Sorry for not describing my scenario.

The issue we have in our version system plugin is the following.

In CDT we select a project. Then we select properties->c/c++ builders-> changing build configuration.

This triggers a checkout .cproject file. What happens now is that a "Progress Information" Dialog opens up and it will interfer with "Checkout" Dialog in our plugin and Eclipse hangs.

from validateEdit() a call is done creating an instance of a CheckoutDialog.

What I want to do is to wait for "Progression Information" Dialog to finnish (sometimes I am lucky and it does ...) and then show my "Checkout" Dialog. But I don't have control over the "Progress Information" Dialog.

Any ideas?

br,

//mike


Re: How to check if UIThread is finnished? [message #758501 is a reply to message #758479] Wed, 23 November 2011 13:39 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
On 2011-11-23 13:22, Mikael Petterson wrote:
> The issue we have in our version system plugin is the following.
>
> In CDT we select a project. Then we select properties->c/c++ builders->
> changing build configuration.
>
> This triggers a checkout .cproject file. What happens now is that a
> "Progress Information" Dialog opens up and it will interfer with
> "Checkout" Dialog in our plugin and Eclipse hangs.
>
> from validateEdit() a call is done creating an instance of a
> CheckoutDialog.
>
> What I want to do is to wait for "Progression Information" Dialog to
> finnish (sometimes I am lucky and it does ...) and then show my
> "Checkout" Dialog. But I don't have control over the "Progress
> Information" Dialog.
> Any ideas?

Unfortunately only very limited, because I have not worked yet with the
above mentioned APIs. But conceptually it looks like a bad idea to wait
for a "finish" of the UI thread (which is not finished, of-course. I
assume you want to know, when the UI event queue is empty). I would
search for a customization point that allows you to inject your handler
to be sure that this is sequenced *after* that. E.g. assuming that above
progress is caused by an Eclipse Job, what about adding an
IJobChangeListener to this job and to wait for done() event? What is
your current approach to show your own dialog anyway? This could also
easily be the root of the problem (which looks like causing a dead lock
to me).

HTH & Greetings from Bremen,

Daniel Krügler
Re: How to check if UIThread is finnished? [message #758679 is a reply to message #758501] Thu, 24 November 2011 08:28 Go to previous messageGo to next message
Mikael Petterson is currently offline Mikael Petterson
Messages: 152
Registered: July 2009
Senior Member
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 11:57 Go to previous message
Daniel Krügler is currently offline Daniel Krügler
Messages: 853
Registered: July 2009
Senior Member
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
Previous Topic:Setting a Preference value programmaticly : DISABLE_OPEN_EDITOR_IN_PLACE
Next Topic:Common Navigator Framework - Keeping models in sync with view
Goto Forum:
  


Current Time: Tue Sep 30 16:04:45 GMT 2014

Powered by FUDForum. Page generated in 0.02000 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software