Archive for January 16th, 2008
It can’t be done! (Ok maybe it can)
by brian on Jan.16, 2008, under abundance
Came across this poem and thought it inspirational
It Couldn’t Be Done
Somebody said that it couldn’t be done,
But he with a chuckle replied
That maybe ” it couldn’t,” but he would be one
Who wouldn’t say so till he’d tried.
So he buckled right in with the trace of a grin
On his face. If he worried, he hid it.
He started to sing as he tackled the thing
That couldn’t be done, and he did it.
Somebody scoffed: ” Oh, you’ll never do that;
At least no one ever has done it.”
But he took off his coat and he took off his hat,
And the first thing we knew he’d begun it.
With a lift of his chin and a bit of a grin,
Without any doubting or quiddit,
He started to sing as he tackled the thing
That couldn’t be done, and he did it.
There are thousands to tell you it cannot be done;
There are thousands to prophesy failure;
There are thousands to point out to you one by one
The dangers that wait to assail you.
But just buckle in with a bit of a grin;
Just take off your coat and go to it;
Just start in to sing as you tackle the thing
That ” cannot be done,” and you’ll do it.
From Edgar A. Guest
Firing an event from within a thread. (At least one way)
by brian on Jan.16, 2008, under .NET, c#, coding
It took me forever to think of this easy method of firing an event from with a thread to the main thread. In searching the web I found several complicated methods that either didn’t work or won’t worth the hassel. But it turns out to be incredible simple and easy to do. The only caveat is that the event subscriber must be a System.Windows.Forms.Control or derived from one
Basically you just get the control target of the delegate and use it’s BeginInvoke or Invoke method and .Net does the rest.
private void DoCommandFinished(Command cmd)
{
if ( null != CommandFinished )
{
System.Windows.Forms.Control c = CommandFinished.Target as System.Windows.Forms.Control;
if (null != c)
{
c.BeginInvoke(CommandFinished, cmd);
}
}
}
I checked this method in my main window thread with the InvokeRequired function. It worked well.
