The name is a bit misleading but RuntimeOperations can be considered a higher level wrapper over threads but is more of a way of executing calculations or functions that be paused and continued.
This works by executing your code in cycles and each cycle returns a state, which is passed to the next cycle of your code and so on. Take a look at the VB.NET example below. It is perofmring the Collatz Conjecture on 27:
Imports Carbon.Operations Public Class Program Public Shared Sub Main() Dim oper = RuntimeOperationsHelper.CreateOperation( Sub(handler As Carbon.Operations.RuntimeOperationHandle(Of BasicRuntimeOperationState), state As BasicRuntimeOperationState) 'During every cycle, this body of code is called. System.Threading.Thread.Sleep(1000) 'Simulate delay to showcase pausing and continuing If state.Value = 1 Then 'Check the previous state and if its equal to 1. handler.Return( RuntimeOperationsHelper.CreateBasicStateFromValue(1)) 'If its equal to one. Stop the operation as successful and return 1 Else If state.Value Mod 2 = 0 Then handler.Pass( RuntimeOperationsHelper.CreateBasicStateFromValue( state.Value / 2)) 'If the previous state is divisible by 2, divide it by 2 and pass it to the next cycle. Else handler.Pass( RuntimeOperationsHelper.CreateBasicStateFromValue( state.Value * 3 + 1)) 'Otherwise, multiple by 3 and add 1 to the previous state, then pass it to the next cycle. End If End If End Sub, "Performing the collatz conjecture..") Console.WriteLine("Running operation test..") oper.Start( RuntimeOperationsHelper.CreateBasicStateFromValue(27)) 'Start the operation ''Below simulates a test by waiting on the operation and pausing and continuing to simulate usage. Dim i = 0 While (True) System.Threading.Thread.Sleep(10) i += 1 If i = 5 Then oper.Pause() Console.WriteLine("Operation paused...") System.Threading.Thread.Sleep(3000) ElseIf i = 10 Then oper.Continue() Console.WriteLine("Operation continued...") ElseIf i = 50 Then Return 'Exit End If End While End Sub End Class
Theres more features where that come from, like a simplied MVVM-based model and also extended wrappers around System.Threading.Tasks.Task.
You can find the source code on Github and/or you can wait for the NuGet package.
If you do build it, let me know if you have any suggestions or questions.
This post has been edited by Amrykid: 22 December 2011 - 11:00 AM