fixed bug in message loop

state would not be disposed by message loop (casting wrong value as Idisposable)
replaced attempt with try/catch