When you say 'Cancel Workflow' do you mean you want to prevent the rest of the workflow activities from executing? If that is the case, I think there are several different things you could do in a server code event:
- You could set an outcome for the activity that has a line rule to an activity with no outcomes
- You could goto an activity that has no outcomes
K2.GotoActivity("Activity Name");
- You could expire the current activity if it is not in a parallel path
K2.ExpireActivity(K2.ActivityInstanceDestination.Activity.Name);
There are even a couple more actions under the SourceCode.Workflow.Management API, but I think I'd try one of the above first.