I'm writing a program that construct a huge diagram. Also this diagram can be save to png file. I have no problems when I render my diagram on WPF canvas. The problem start when I trying save it to file. DrawingContext.DrawText stop drawing the text with size==10 when horizontal text position becomes more than 11K pixels!
Here is the code that shows this effect.
I create simple WPF application project and create one class (MainViewControl):
Here is the code for MainViewControl.cs:
class MainViewControl : FrameworkElement
publicvoid Draw(DrawingContext context)
for (var i = 0; i < Width / 100; i++)
var text = new FormattedText((i * 100).ToString(CultureInfo.InvariantCulture), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 10, Brushes.Blue);
var textPos = new Point((double)i * 100f + 0.789 - text.Width / 2, Height / 2 - text.Height / 2);
context.DrawLine(new Pen(Brushes.Red, 1.0), new Point(i * 100, 0), new Point(i * 100, Height));
context.DrawRectangle(Brushes.White, null, new Rect(textPos.X, textPos.Y, text.Width, text.Height));
protectedoverridevoid OnRender(DrawingContext context)
And Dispose does not seem to be the answer either.
I am not using the webbrowser class for its visible properties to the user. I am using it to navagate several URL's in a row. This can have a wierd effect where the browser starts sending back load completed messages when the body of the html is not usable and I just want it stopped.
Here's one tough question - I am suspecting Dispatcher deadlock, thus freezing the UI (after I click SaveItems button some number of times).
The following event handler "OnItemsReloaded" is triggered async from another thread ("LoadItems" thread - which holds a lock on an object "ItemsSyncRoot". Another thread ("SaveItems" thread) also competes to lock on to this object.
(So yes, LoadItems thread and SaveItems thread contending for same lock)
Here's the EMPTY Dispatcher.Invoke (Triggered by "LoadItems" thread - a background thread):
If I change above from "Invoke" to "BeginInvoke" - UI no longer freeze! Question is why. (Please note for debugging purpose, event handler Dispatcher delegate is empty! [So no lock in Dispatch.Invoke delegate!]
[SAME, UI don't freeze if I put a "return" before "Dispatcher" invoke!?]
I futher attempted to nail down the scope further by:
(a) Attached Visual Studio debugger to the running/freezed UI - then from Intellitrace, "Breakall"- which reveals that execution of a "Background" thread freeze on attempting to lock(ItemsSyncRoot). Since this is a background thread ("SaveItems" thread) which attempted to lock(ItemsSyncRoot) - this does NOT explains why UI freezed!
(b) Windbg - !syncblk,) then !clrstack - which pointed me to the [Dispatcher.Invoke] as stated above! But what's confusing is, I don't see why an "Empty Dispatcher Invoke" can lead to UI freezing up.
Note that from !syncblk Info=64. I used that in !clrstack command (Is this right?)
Found the answer, share it here to dispel myth Dispatcher.Invoke buggy...
thread A background thread
LoadItems(..) --> This will trigger event "ItemsReloaded", and one UI thread handler handles this. Problem is, "SaveItems" button clicked after initial lock to SomeSingleton but before "ItemsReloaded" fired.<br/>
UI Thread handler for "ItemsLoaded":
// Holds no lock statement here!!!<br/>
// But Dispatcher.Invoke is blocked by thread B (UI thread) indefinitely - see next...<br/>
Thread B (UI Thread)
lock(SomeSingleton) // Block by thread A, thus hanging UI thread.
// blocked indefinitely as Thread A cannot return until "ItemsLoaded" (thus its UI handler) is fired.
Hope it helps.
What's INTERESTING though, is Windbg pointed me to lock statement in THREAD-A, whereas, if I attached Visual Studio debugger (with Intellitrace), it lead me straight to lock statement in THREAD-B
Also, in this situation, there's only one "SingletonLock" - not the textbox deadlock situation where you have lock(LockA) and lock(LockB) with two threads locking in reverse order.
You may have only one lock instruction, but there is another lock.
The Invoke itself is a kind of lock. It will wait until the action finishes. That's why it dead-locks (and the BeginInvoke does not, as it does not wait).
Regarding my service class attribute, [EnableClientAccess(RequiresSecureEndpoint = true)], I was wondering if it was possible to change the value of RequiresSecureEndpoint based on a value I can set in the config file. e.g.
When I click the button to load another component, the LoadCommand has been set in the constructor but never seems to be called on the button click.
I have been converting a VB project to C# to try and learn the language and maybe I have missed something in the translation.
I have other containers injecting into the shell that don't use Command calls that are working fine.
I don't speak Idiot - please talk slowly and clearly
Dunno if you want these kinds of comments, so feel free to ignore them if you are offended , but your question IS answered below.
1) Bad practice to litter your code with 'this'. It's not needed as its implied.
2) Bad practice to use an interface to reference a concrete class inside of the class itself (public ICommand LoadSomeViewCommand)... its a RelayCommand, not an ICommand. You should only pass it around externally as an ICommand.
3) Your implementation of RelayCommand isn't correct. You should not need all that new Action, new Predicate garbage.
4) Your non-generic RelayCommand should not take any params. RelayCommand<T> is the one that takes a param and that one should be type safe. Don't pass in an object, pass in the real type.
5) *THE ANSWER TO YOUR QUESTION* You can't databind to a variable. Only properties.
6) If you are using UnityContainer, or any other DI container. USE IT. In your SomeView contructor, you have the unity container reference, but aren't using it to create the object.
7) Better to use an attached property to set your data context, so you get rid of all the hand wiring with a code behind.
Cheers, i am not easily offended and want to learn this the correct way - very hard without someone to bounce off. As I said, this is from a VB project I am converting to try nd get the hang of the language.
You have given me a few things to work on,and probably learn from.
I don't speak Idiot - please talk slowly and clearly
"I have sexdaily. I mean dyslexia. Fcuk!"
Driven to the arms of Heineken by the wife
Last Visit: 31-Dec-99 18:00 Last Update: 22-Oct-17 2:11