Johannes Hofmeister
Check me out on the web at Cessor.
Visual Studio Achievements
I am a student of commercial computer science, currently located in Heidelberg, Germany
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
The Future of C#
Nov 05, 2008 at 5:46 AMThe "dynamic" stuff needs to be taken with criticism - I guess many untrained developers such as students might mistake C# for a scripting language. I am afraid of the day I get a piece of code saying 1000x dynamic and a 1000 times var and not a single type name in it. . .
Service Enabling Workflows
Sep 03, 2008 at 4:29 AMThe biggest problem is to route the the message from the Service Object to the UI Control. This has to be done by invoking a delegate on the form or the control itself, gently asking it do display someting for you. I usually do it with events exposed by the service class:
// IMessageService.cs:
[ExternalDataExchange]
public interface IMessageService
{
void SendMessage(string message);
}
//MessageService.cs
public class MessageService : IMessageService
{
public event EventHandler<MessageReceivedEventArgs> MessageReceived;
public void SendMessage(string message)
{
if (MessageReceived != null)
MessageReceived(this,
new MessageReceivedEventArgs(
WorkflowEnvironment.WorkflowInstanceId,
message));
}
}
The EventArgs object for this Event is a simple class derived from ExternalDataEventArgs, that contains a string property for the message. To identify the sender the ExternalDataEventArgs Ctor always requires a Guid.
Now you can instantiate the service from the host application, then register to the MessageReceived Event. When received you can build a delegate that will be invoked on the form to change properties of the controls to display the message
// in form load:
ExternalDataExchangeService service = new ExternalDataExchangeService();
_runtime.AddService(service);
_messageService = new GuessingGameService();
service.AddService(_gameService);
_messageService.MessageReceived += new EventHandler<MessageReceivedEventArgs>(_messageService_MessageReceived);
// the delegate
private delegate void UpdateDelegate();
void _messageService_MessageReceived(object sender, MessageReceivedEventArgs e)
{
UpdateDelegate theDelegate = delegate()
{
lblMessage.Text = e.Message;
};
_instanceId = e.InstanceId;
this.Invoke(theDelegate); // invokes the delegate on the form updating the control.
}
-----
As there has no example been distributed so far - link still broken - i decided to do it on my own, and i hope this helps. if your want my sample code (very similar to this) just message me.