Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#246 Fix for inappropriate disposal #254

Merged
merged 3 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/Examples/CSharp NativeImport/CallbackEx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ namespace NativeImport_Examples
{
public struct MyUserDataClass
{
public int Value = 1234;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the primary change. Without it the code doesn't compile

public int Value;

public MyUserDataClass()
{
Value = 1234;
}
}

class CallbackEx
Expand Down
16 changes: 9 additions & 7 deletions src/libplctag/NativeTagWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,11 @@ public async Task InitializeAsync(CancellationToken token = default)

using (cts.Token.Register(() =>
{
Abort();
RemoveEvents();

if (createTasks.TryPop(out var createTask))
{
Abort();
RemoveEvents();

if (token.IsCancellationRequested)
createTask.SetCanceled();
else
Expand All @@ -344,6 +344,8 @@ public async Task InitializeAsync(CancellationToken token = default)
if(GetStatus() == Status.Pending)
await createTask.Task;

ThrowIfStatusNotOk(createTask.Task.Result);

_isInitialized = true;
}
}
Expand Down Expand Up @@ -372,10 +374,10 @@ public async Task ReadAsync(CancellationToken token = default)

using (cts.Token.Register(() =>
{
Abort();

if (readTasks.TryPop(out var readTask))
{
Abort();

if (token.IsCancellationRequested)
readTask.SetCanceled();
else
Expand Down Expand Up @@ -415,10 +417,10 @@ public async Task WriteAsync(CancellationToken token = default)

using (cts.Token.Register(() =>
{
Abort();

if (writeTasks.TryPop(out var writeTask))
{
Abort();

if (token.IsCancellationRequested)
writeTask.SetCanceled();
else
Expand Down