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

Replace ActionItem replace with a more strongly typed approach to safe a few allocations #188

Closed
wants to merge 3 commits into from

Conversation

danielmarbach
Copy link
Contributor

No description provided.

@danielmarbach
Copy link
Contributor Author

@xinchen10 Thanks for looking into this

_ = Task.Factory.FromAsync(
(stateParameter, c, callbackState) => ((Action<TState>)callbackState).BeginInvoke(stateParameter, c, callbackState),
r => ((Action<TState>)r.AsyncState).EndInvoke(r), state,
callback);
}
Copy link
Member

Choose a reason for hiding this comment

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

If there is an exception from callback, the process will crash with the current code due to unhandled exception. After the change it will not happen because the exception is preserved in the task but no one is awaiting on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware that you want the application to crash in such a case which I find super awkward since you are essentially a library and the behavior should be up to the application to decide

In theory I could try catch on end invoke and queue the exception as a waitcallback. Thoughts?

ThreadPool.QueueUserWorkItem(new WaitCallback(ignored =>
{
throw originalException;
}));

Copy link
Member

Choose a reason for hiding this comment

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

As a library it has to consider exceptions from callbacks fatal because there is no safe strategy to handle it. One example is Timer from the framework. I believe all callbacks from the library handle exceptions as appropriate. This method is also used to invoke user callbacks. In case of user callbacks not handling exceptions it should let the app crash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added it but I'm no longer sure it is worth it. Otherwise I drop it. No hard feelings

@xinchen10
Copy link
Member

Close the PR for now. Will revisit later if needed.

@xinchen10 xinchen10 closed this Aug 10, 2021
@danielmarbach danielmarbach deleted the action-schedule branch December 11, 2021 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants