RobertAlanGustafsonII
Active member
- Joined
- Sep 16, 2023
- Messages
- 31
- Programming Experience
- 10+
WHAT I HAVE:
Visual Basic 2019, .NET 4.6+, WinForms
MY ISSUE:
I'm creating a custom WinFroms control that's supposed to do several things, including the one I'm talking about here--which is why I hope that the solution to my question doesn't require a lot of complex, convoluted, confusing code here. I want to save a large amount of data to a file asynchronously with members like the following, using public methods SaveAsync and CancelAsync, and public events SaveProgressChanged and SaveComplete:
I want the background task to save the data in increments of a certain size, each time firing SaveProgressChanged to report progress thereafter, and to fire SaveComplete, with data on whether the proces finsihed, cancelled, or was aborted by error, at the end. I've been studying help-file examples on asynchronous operations and file I/O but I'm not sure how best to get all my specific desired results.
What's the best way to do it? My options seem to be using FileStream asynchrounously (no help-file examples apper to exist, though, for how to write multiple BeginWrite/EndWrite blocks in the same stream, one after the other) or using BackgroundWorker with FileStream (synchronously with multiple Write blocks, or asynchronously with multiple BeginWrite/EndWrite blocks [again, how is that done?], inside the DoWork event). Maybe there are other ways. What's the most reliable yet simple way to do this? I don't to write a ton of spagetti code, but I want to get it done.
Please answer ASAP, and keep it as simple as possible.
Visual Basic 2019, .NET 4.6+, WinForms
MY ISSUE:
I'm creating a custom WinFroms control that's supposed to do several things, including the one I'm talking about here--which is why I hope that the solution to my question doesn't require a lot of complex, convoluted, confusing code here. I want to save a large amount of data to a file asynchronously with members like the following, using public methods SaveAsync and CancelAsync, and public events SaveProgressChanged and SaveComplete:
Methods and events for Asynchronous save:
Private Sub BackgroundTask()
' logic to perform asynchronous save operation in background
End Sub
Public Event SaveProgressChanged(sender As Object, e As ProgressChangedEventArgs)
Public Event SaveCompleted(sender As Object, e As AsychCompletedEventArgs)
Public Sub SaveAsync(ByVal FileName As String)
' logic to initiate asynchronous save
End Sub
Public Sub CancelAsync()
' logical to cancel asnchronous save
End Sub
I want the background task to save the data in increments of a certain size, each time firing SaveProgressChanged to report progress thereafter, and to fire SaveComplete, with data on whether the proces finsihed, cancelled, or was aborted by error, at the end. I've been studying help-file examples on asynchronous operations and file I/O but I'm not sure how best to get all my specific desired results.
What's the best way to do it? My options seem to be using FileStream asynchrounously (no help-file examples apper to exist, though, for how to write multiple BeginWrite/EndWrite blocks in the same stream, one after the other) or using BackgroundWorker with FileStream (synchronously with multiple Write blocks, or asynchronously with multiple BeginWrite/EndWrite blocks [again, how is that done?], inside the DoWork event). Maybe there are other ways. What's the most reliable yet simple way to do this? I don't to write a ton of spagetti code, but I want to get it done.
Please answer ASAP, and keep it as simple as possible.
Last edited: