Cannot cast type "PooledAwait.ValueTaskCompletionSource1[System.Object]" to type "System.Threading.Tasks.TaskCompletionSource1[System.Object]"
tossorrow opened this issue · 4 comments
tossorrow commented
I created 2 buttons in winform app.
SecsGem? _secsGem;
HsmsConnection? _connector;
CancellationTokenSource _cancellationTokenSource = new CancellationTokenSource();
private async void StartButton_Click(object sender, EventArgs e)
{
_secsGem?.Dispose();
if (_connector is not null)
{
await _connector.DisposeAsync();
}
var options = Options.Create(new SecsGemOptions
{
IsActive = false,
IpAddress = "127.0.0.1",
Port = 5000,
SocketReceiveBufferSize = 65535,
DeviceId = (ushort)0,
});
var logger = new SecsLogger();
_connector = new HsmsConnection(options, logger);
_secsGem = new SecsGem(options, _connector, logger);
_ = _connector.StartAsync(_cancellationTokenSource.Token);
await foreach (var primaryMessage in _secsGem.GetPrimaryMessageAsync(_cancellationTokenSource.Token))
{
recvBuffer.Add(primaryMessage);
}
}
private async void EndButton_Click(object sender, EventArgs e)
{
if (!_cancellationTokenSource.IsCancellationRequested)
{
_cancellationTokenSource.Cancel();
_cancellationTokenSource.Dispose();
}
if (_connector is not null)
{
await _connector.DisposeAsync();
}
_secsGem?.Dispose();
_cancellationTokenSource = new CancellationTokenSource();
_secsGem = null;
recvBuffer.Clear();
}
I click start button and then click end button, exception occured in _cancellationTokenSource.Cancel()
.
Cannot cast an object of type "PooledAwait.ValueTaskCompletionSource1[System.Object]" to type "System.Threading.Tasks.TaskCompletionSource1[System.Object]".
mkjeff commented
Could you provide a complete source repository?
That would be helpful for the people wanna help.
tossorrow commented
Thanks for reply, here‘s the complete source repository https://gitee.com/tossorrow/forissue_secs.git
mkjeff commented
I have addressed the issue in this commit
If the problem solves, I'd publish a new version later.
tossorrow commented
problem solved, thx