none
task<F> dpes not contain definition for Dispose and no extension method... RRS feed

  • Question

  • Hello;

    I have two project both in .Net 4 (and both PCL libraryes).In the first one Task.Dispose() exist in the second one no. As I read that dispose is useless in most of case (cf: here). I first thoug they have remove the inheritance but they talk about .net 4 wich I use.

    Monday, August 31, 2015 2:32 PM

Answers

  • Hi Aurelien312,

    According to your description, you are using different dlls. Your first project using the mscorlib.dll is coming from the .NETPortable folder which used for creating a Class Library that targets multiple platforms at one time. Most PCL classes and BCL classes are same, but some of them are different.

    Best Regards,
    Li Wang

    • Marked as answer by Aurelien312 Monday, September 7, 2015 9:38 AM
    Thursday, September 3, 2015 6:46 AM
    Moderator

All replies

  • The System.Threading.Tasks.Task class, which is the base class for the generic System.Threading.Tasks.Task<TResult> class, does implement the IDisposable interface.

    But in most cases you don't need to actually dispose the Task object. Please refer to the following page for more information about this: http://stackoverflow.com/questions/3734280/is-it-considered-acceptable-to-not-call-dispose-on-a-tpl-task-object

    Do I need to dispose of Tasks?: http://blogs.msdn.com/b/pfxteam/archive/2012/03/25/10287435.aspx

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Monday, August 31, 2015 4:11 PM
  • I have already seen the pages you link but thanks. That was only to understand the difference because System.Threading.Tasks.Task<TResult> inherit from System.Threading.Tasks.Task... and both doesn't implement IDisposable (In my without dispose project)...
    Tuesday, September 1, 2015 10:22 AM
  • Both? Since System.Threading.Tasks.Task<TResult> inherits from System.Threading.Tasks.Task which does implement the IDisposable interface, a System.Threading.Tasks.Task<TResult> is implicitly an IDisposable. You should make sure that "task<F>" is really a System.Threading.Tasks.Task<TResult> and not some other kind of task.

    Please upload a reproducible sample of your issue to OneDrive and post the link to it here if you need any further help.

    Hope that helps.

    Please remember to mark all helpful posts as answer to close the thread and please start a new thread if you have a new question.

    Tuesday, September 1, 2015 12:18 PM
  • I have two different version. Weird the PCL version use the 2.0.5.0. Since dispose was mostly useless I thougth that the newer was the one without dispose but not.

    #region Assembly mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes
    // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile\Profile328\mscorlib.dll
    #endregion
     
    namespace System.Threading.Tasks {
        //
        // Summary:
        //     Represents an asynchronous operation.
        public class Task : IAsyncResult {

    and

    #region Assembly mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    // C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
    #endregion
     
    using System.Diagnostics;
     
    namespace System.Threading.Tasks {
        //
        // Summary:
        //     Represents an asynchronous operation.
        [DebuggerDisplay("Id = {Id}, Status = {Status}, Method = {DebuggerDisplayMethodDescription}")]
        [DebuggerTypeProxy(typeof(SystemThreadingTasks_TaskDebugView))]
        public class Task : IThreadPoolWorkItem, IAsyncResultIDisposable {

    I don't know why the PCL project reference both Version=4.0.0.0 and Version=2.0.5.0. But I htinks that where the bug come from.


    • Edited by Aurelien312 Wednesday, September 2, 2015 9:28 AM space between sample
    Wednesday, September 2, 2015 9:26 AM
  • Hi Aurelien312,

    According to your description, you are using different dlls. Your first project using the mscorlib.dll is coming from the .NETPortable folder which used for creating a Class Library that targets multiple platforms at one time. Most PCL classes and BCL classes are same, but some of them are different.

    Best Regards,
    Li Wang

    • Marked as answer by Aurelien312 Monday, September 7, 2015 9:38 AM
    Thursday, September 3, 2015 6:46 AM
    Moderator