private readonly object _sync= new object(); public IAsyncResult BeginInvoke(Delegate method, object[] args) { var result = new SimpleAsyncResult(); ThreadPool.QueueUserWorkItem( delegate { result.AsyncWaitHandle = new ManualResetEvent(false); try { result.AsyncState = Invoke(method, args); } catch (Exception exception) { Debug.WriteLine(exception.Message); Debug.WriteLine(exception.StackTrace); result.Exception = exception; } result.IsCompleted = true; }); return result; } public object EndInvoke(IAsyncResult result) { if (!result.IsCompleted) { result.AsyncWaitHandle.WaitOne(); } return result.AsyncState; } public object Invoke(Delegate method, object[] args) { lock (_sync) { return method.DynamicInvoke(args); } } public bool InvokeRequired { get { return true; } } public class SimpleAsyncResult : IAsyncResult { private object _state; public bool IsCompleted { get; set; } public WaitHandle AsyncWaitHandle { get; internal set; } public object AsyncState { get { if (Exception != null) { throw Exception; } return _state; } internal set { _state = value; } } public bool CompletedSynchronously { get { return IsCompleted; } } internal Exception Exception { get; set; } }Want to read more?
Monday, September 9, 2013
ISynchronizeInvoke implementation example
Put the following code for classes you want to implement ISynchronizeInvoke should do the job
How to put code snippet into blogger like blogspot
// Comment public class Testing { public Testing() { } public void Method() { /* Another Comment on multiple lines */ int x = 9; } }Reference here: http://www.craftyfella.com/2010/01/syntax-highlighting-with-blogger-engine.html
[Self Reference] Bug Lists
20 Sep 2013
- if…else.. do not consider last redundant assignment
- when dividing, denumerator can be zero
8 Sep 2013
- Do not initialize class values before using it - Do not initialize the RuntimeAdapter for InitialState (leave empty), when using RuntimeAdapter
- == and !=, if(root.Count==1) throw (only allow once) -> Suppose to be !=1
-----
- wrong sequence - Clear the ConcreteServices at the wrong place just after populating it, it should be just before populating it
- missed item - case.execute() is not implemented
- missed item - the switch does exert the event to partialModelState
- redundant call - put two calls in start and internal start for simulate()
- wrong name - when copy paste forget to change all the names
- Not setting global one - declare a lobal Simulator sm, and didn't set to global one
- terminate event not sent - skip is never called as it won't evoluate to that event, correct way to send terminate event is via the Bprocess execute()
- Unexpected - parallel.run(…), in … throw exception (a duplicate var can solve the problem)
- parallel.invoke bug can't throw outside: http://stackoverflow.com/q/18764007/1497720
----
Previous two days
- not initialize v with maximum when doing v=min(v, value)
- not initialize v with zero and maximum separately, when v has to do with min and plus
- in switch, change the case activity value
- does not understand that geteventid, is a state with previous edges
- using a the terminal states without initializing it with value
- Index out of bound - action0Col[1] == "if", but action0Col may not have index 1 (e.g., for atomic action)
- copy paste - result.Add(new ActionPair(actionPair.Value[0], actionPair.Value[1], action0Col[2] == "c"));
- not assigning value to instance - not assigning the value to Available of Nonfunctional Attribute, but assign to a variable totAvailability
- split value problem(knowledge problem) - [if:0:c] split becomes {"[if","0","c]"}
- copy paste - avgResponseTime += nf.ResponseTime; should be avgResponseTime += nf.avgResponseTime;
- Concept problem - in AggregateActions firstResponseTime and firstAvgResponseTime treat the same
- "a:name:<empty>", string split, then only have two columns, access 2 index out of bound
- Value is null, lock{..}{}..this .. is empty!
- Queue and trace not initialize when accessed
Subscribe to:
Posts (Atom)