Daily update on 20250618-051714 by Nitload Youmu. Additional Message : Brief support to collection operation in EXPRESS. A collection type added in core lib and compilestack.
Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
@@ -38,12 +38,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Threading
|
||||
{
|
||||
public class CancellableTask:IDisposable
|
||||
public class CancellableTask : IDisposable
|
||||
{
|
||||
|
||||
private bool disposedValue;
|
||||
private CancellationTokenSource cts;
|
||||
private protected Action<CancellationToken> _startup;
|
||||
private protected Task _internalTask;
|
||||
private CancellationTokenSource cts;
|
||||
private bool disposedValue;
|
||||
|
||||
private protected CancellableTask()
|
||||
{
|
||||
@@ -82,9 +83,23 @@ namespace StgSharp.Threading
|
||||
_internalTask.Wait();
|
||||
}
|
||||
|
||||
// ~CancellableTask()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose( disposing: true );
|
||||
GC.SuppressFinalize( this );
|
||||
}
|
||||
|
||||
public static CancellableTask Run( Action<CancellationToken> startup )
|
||||
{
|
||||
CancellableTask ret = new CancellableTask { _startup = startup };
|
||||
CancellableTask ret = new CancellableTask
|
||||
{
|
||||
_startup = startup
|
||||
};
|
||||
ret._internalTask = Task.Run( ret.InternalAction );
|
||||
return ret;
|
||||
}
|
||||
@@ -104,10 +119,30 @@ namespace StgSharp.Threading
|
||||
[MethodImpl( MethodImplOptions.AggressiveInlining )]
|
||||
internal void InternalAction()
|
||||
{
|
||||
//Console.WriteLine($"Task {Task.CurrentId} is running.");
|
||||
_startup( Cts.Token );
|
||||
}
|
||||
|
||||
protected virtual void Dispose( bool disposing )
|
||||
{
|
||||
if( !disposedValue )
|
||||
{
|
||||
if( disposing )
|
||||
{
|
||||
if( IsCompleted )
|
||||
{
|
||||
cts.Dispose();
|
||||
_internalTask.Dispose();
|
||||
} else
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Cannot dispose a cancellable task before completed" );
|
||||
}
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static implicit operator Task( CancellableTask task )
|
||||
{
|
||||
return task._internalTask;
|
||||
@@ -118,36 +153,5 @@ namespace StgSharp.Threading
|
||||
Cts.Dispose();
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (!disposedValue)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
if (IsCompleted)
|
||||
{
|
||||
cts.Dispose();
|
||||
_internalTask.Dispose();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new InvalidOperationException("Cannot dispose a cancellable task before completed");
|
||||
}
|
||||
}
|
||||
|
||||
disposedValue = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ~CancellableTask()
|
||||
// {
|
||||
// Dispose(disposing: false);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(disposing: true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user