|
The NULL DeveloperI have some tasks which are done on the UI thread, and I have to show progress on a separate dialog, which is been shown on a worker thread.
This defeats the purpose of a worker thread (because it cannot happily do its work on the background), and defeats the purpose of having the main thread as an UI thread (which is a thread with a message pump and you have blocked it with some lengthy processing). Blocking the message pump is just atrocious.
The NULL DeveloperEvery thing is working fine, except for one glitch - if a message box is shown in the ...
No! The glitch is that you are blocking the application's message pump. Just please have the worker thread do the lengthy processing and let it also notify the UI of the progress.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Rajesh, I fully agree with you, as I had mentioned and as I had said, this scenario cannot be changed because these are already existing applications written that way. And that application is HUUUUUGE!
So I had to do it the other way.
"Do first things first, and second things not at all."
— Peter Drucker.
|
|
|
|
|
I agree with the others that the design is flawed but you seem to be aware of that.
You could wrap the message box call into your own static method with the call to the backgroundThread and MessageBox.Show, and call your method instead each time.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
Dave, that will serve the purpose for MessageBox only. What about existing custom modal dialog boxes?
"Do first things first, and second things not at all."
— Peter Drucker.
|
|
|
|
|
The NULL Developerand I have to show progress on a separate dialog, which is been shown on a worker thread
So you're saying that the progress dialog is launched by the background thread instead of the UI thread? If so, there's your problem. ALL UI, including the progress dialog should be created on the UI thread, not a background thread. You can invoke a method from the background thread to update the progress bar. If you can't change this, you're pretty much screwed. There is no notification your app is about to create a new dialog.
|
|
|
|
|
|
The CBT Hook is what would be looking for but it's a huge overkill solution to the problem of showing the window on the wrong thread in the first place.
|
|
|
|
|
I agree with Rajesh. This sounds like a very bad design to me. What are you ultimately trying to achieve with this?
|
|
|
|
|
Hello,
I just performed 8 searches on CodeProject for "Rich TextBox Ruler" because I want to add a ruler to my text editor project and, I also changed the search phrase around but it kept on showing "No results" page but the other day there were heaps... Does anybody know how I can add a ruler to my text editor project, or know any links for articles?
Thanks all,
jason
|
|
|
|
|
How about this[^] one?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
a metric ruler?
the EU will only go that far.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
hehehe, I'm not sure of the correct name for it, but I'd like the same type of "ruler" as you would see in Microsoft Word, for example.
Jase.
|
|
|
|
|
Hi
http://www.codeproject.com/KB/miscctrl/ruler.aspx
This might help u
|
|
|
|
|
Thank you both for your links. Just what I was looking for. I'm very happy!
Jase.
P.S. Maybe I need to reset my cache... I don't know why searches are not returning any results.
|
|
|
|
|
Can anyone explain why the following won't compile and a possible solution...
string strSequence = (view.GetFocusedValue().ToString() == String.IsNullOrEmpty ? view.GetFocusedValue().ToString() : "");
I get the following error...
Error 16 Operator '==' cannot be applied to operands of type 'string' and 'method group'.
Many Thanks
|
|
|
|
|
String.IsNullOrEmpty is a method, not a property. Try to use this instead:
string strSequence = (string.IsNullOrEmpty(view.GetFocusedValue().ToString()) ? view.GetFocusedValue().ToString() : string.Empty);
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
.IsNullOrEmpty is a method
change to .Empty
|
|
|
|
|
stancrm wrote: change to .Empty
Trust me, having if conditions that change variable contents is a good way to really mess your code up and cause such nasty bugs! I don't think Empty() does quite what you think it does...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
string.Empty doesn't change the value of the string unless you assign it, and the OP was doing an equality test. What do you think it does?
If his test is if (value == string.Empty) , this doesn't change value .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
ms fxcop says:
dont use : (value == string.Empty)
use: (value.Length == 0)
|
|
|
|
|
Indeed, but that's for a separate issue (i.e. it's quicker to check the length). The fuller check is to use string.IsNullOrEmpty to check because the value might be null or it might be empty, in which case value.Length would throw an ArgumentNullException .
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: string.Empty doesn't change the value of the string unless you assign
You are absolutely right, and I grovel, lots. I can only blame complete and utter brain failure, brought on by unexpected sunshine.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Ok wait, what are you trying to achieve? This code (even if I pretend that the == works) does not do anything useful.
Suppose view is null: NullReferenceException
Or the value returned by GetFocusedValue is null: NullReferenceException
Or the value returned by ToString is null: strSequence is null
ToString returns "": strSequence is ""
ToString returns anything else: strSequence is ""
So you either get an exception, or you get a useless value in strSequence. What's the deal here? What did you want to do?
If what you want is: the value of view.GetFocusedValue().ToString() if it isn't null, or "" if it is null
Then you could do:
string strSequence = view.GetFocusedValue().ToString() ?? "";
Disclaimer: I just woke up, it's entirely possible that I'm not making any sense at all - sorry!
|
|
|
|
|
Harold, Thanks for that - I think that is exactly what I need. Basically all I want to do is check if View.GetFocusedValue... is null. If it is null then assign a "" otherwise use the View.GetFocusedValue. What will happen with it if the value comming back happens to be DBNull.Value (assuming I was doing something with a dataset.
Thanks
|
|
|
|