Bug 21027 - Task.Start hangs with subclass of Task
Summary: Task.Start hangs with subclass of Task
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.4.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-07-01 15:48 UTC by John Miller [MSFT]
Modified: 2014-07-04 04:41 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description John Miller [MSFT] 2014-07-01 15:48:35 UTC
### Overview: 

    Task.Start hangs in certain conditions.

### Steps to Reproduce: 

    Install/start the app using the debugger.
    Stop the app with the square-in-circle button on the IDE.
    Double tap and "kill" the app on the phone.
    Tap the app icon to start it - it starts up fine.
    Tap the home button to get back to the springboard.
    Tap the app icon to start it, and it hangs in task.Start().

### Actual Results: 

    The app will hang on task.Start()

### Expected Results: 

    No hang.

### Build Date & Platform: 

    XI 7.2.4.4
    Mono 3.4.0

### Additional Information: 

    I only have this code as an example, no test case.

> public static NcTask Run (Action action, string name)
> {
> WeakReference taskRef = null;
> Console.WriteLine ("NcTask.Run - A");
> var task = new NcTask (delegate {
> Log.Info (Log.LOG_SYS, "NcTask {0} started.", name);
> action.Invoke ();
> Log.Info (Log.LOG_SYS, "NcTask {0} completed.", name);
> if (!TaskMap.TryRemove (taskRef, out name)) {
> Log.Error (Log.LOG_SYS, "Task {0} already removed from TaskMap.", name);
> }
> });
> Console.WriteLine ("NcTask.Run - B");
> taskRef = new WeakReference (task);
> if (!TaskMap.TryAdd (taskRef, name)) {
> Log.Error (Log.LOG_SYS, "Task {0} already removed from TaskMap.", name);
> }
> Console.WriteLine ("NcTask.Run - C");
> task.Start ();
> Console.WriteLine ("NcTask.Run - D");
> Log.Info (Log.LOG_SYS, "Task {0} started.", name);
> return task;
> }
Comment 1 Marek Safar 2014-07-03 09:01:26 UTC
Where is the app to reproduce with?
Comment 2 John Miller [MSFT] 2014-07-03 14:16:34 UTC
@Marek,

Sorry, per my comment in Additional Information, that is the only code I have. I don't have a complete test case.
Comment 3 Marek Safar 2014-07-04 04:41:34 UTC
This code is very incomplete. How do you know task is of type Task I see only NcTask.

After stubbing the user code it works for me fine.

Test code

using System;
using System.Threading.Tasks;
using System.Collections.Concurrent;

class NcTask : Task
{
	public NcTask (Action d)
		: base (d)
	{
	}
}


class Test
{
	static ConcurrentDictionary<WeakReference, string> TaskMap = new ConcurrentDictionary<WeakReference, string> ();

	static void Main (string[] args)
	{
		Run (delegate {

		}, "aa");
	}

	public static NcTask Run (Action action, string name)
	{
		WeakReference taskRef = null;
		Console.WriteLine ("NcTask.Run - A");
		var task = new NcTask (delegate {
			Console.WriteLine ("NcTask {0} started.", name);
			action.Invoke ();
			Console.WriteLine ("NcTask {0} completed.", name);
			if (!TaskMap.TryRemove (taskRef, out name)) {
				Console.WriteLine ("Task {0} already removed from TaskMap.", name);
			}
		});
		Console.WriteLine ("NcTask.Run - B");
		taskRef = new WeakReference (task);
		if (!TaskMap.TryAdd (taskRef, name)) {
			Console.WriteLine ("Task {0} already removed from TaskMap.", name);
		}
		Console.WriteLine ("NcTask.Run - C");
		task.Start ();
		Console.WriteLine ("NcTask.Run - D");
		Console.WriteLine ("Task {0} started.", name);
		return task;
	}
}