|
Is their a way to sort of serialize the data of a WPF richtextbox to save the formatting of the text in the control so it can be sent to an Access Database? I am working in the .NET framework 3.0.
Any help would be much appreciated
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Use rtf property of richtextbox class to save all text and formatting in database. BTW, now there is WPF forum too
|
|
|
|
|
I forgot about that forum. I just realized it existed just this past weekend, I'll be sure to post this question their. As for the rtf property goes, the WPF richtextbox does not have an RTF property. It uses the new Document class in the System.Windows.Document namespace.
Thanks,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Ops, my mistake. Here is an example that shows how to save/load/print richtextbox in wpf: Save,Load,Print[^]
There is no need to double-post your question.
|
|
|
|
|
Thanks,
I now have so the text is outputted to an Access 2003 database, but now the only thing that I need to know if their is away to databind the XAML or RTF from the Database to the RichTextBox. None of the properties that deal with the RichTextBox content are dependency properties that databinding can be used with.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hi1 i have to start two threads. first thread copy file of 1 GB from source to destination & another copy file of 20 MB from source to destination. both thread uses same method. i run only 2 thread at a time. whenever one thread completes ,i can strat another that uses the same method. how can i know which one is completed so that i can start another?
|
|
|
|
|
|
There's a number of possibilities, for example: Use the the thread's Join method or use an AutoResetEvent to signal between threads.
Standards are great! Everybody should have one!
|
|
|
|
|
there also is the "IsAlive" property of the thread's object
|
|
|
|
|
Here`s a short code snippet:
SNIPPET[^]
The main purpose of this application was to test how critical regions work. In my opinion the first loop (with 'i' as index) should be performed in whole, so the abc variable should have the value of 100000001. Why does it have 88430?
Thank you very much for help in advance
|
|
|
|
|
Where does it say the loop is performed as a whole, without any time slicing? MSDN only says:
Notifies a host that execution is about to enter a region of code in which the effects of a thread abort or unhandled exception might jeopardize other tasks in the application domain
Standards are great! Everybody should have one!
|
|
|
|
|
Well no it's normal - you abort the thread after all.
The CriticalRegion just tells the CLR that you app will have major problems if you run into an exception in this region!
Here is the explanation from MSDN:
Hosts of the common language runtime (CLR), such as Microsoft SQL Server 2005, can establish different policies for failures in critical and non-critical regions of code. A critical region is one in which the effects of a thread abort or an unhandled exception might not be limited to the current task. By contrast, an abort or failure in a non-critical region of code affects only the task in which the error occurs.
For example, consider a task that attempts to allocate memory while holding a lock. If the memory allocation fails, aborting the current task is not sufficient to ensure stability of the AppDomain, because there can be other tasks in the domain waiting for the same lock. If the current task is terminated, other tasks could be deadlocked.
When a failure occurs in a critical region, the host might decide to unload the entire AppDomain rather than take the risk of continuing execution in a potentially unstable state. To inform the host that your code is entering a critical region, call BeginCriticalRegion. Call EndCriticalRegion when execution returns to a non-critical region of code.
Using this method in code that runs under SQL Server 2005 requires the code to be run at the highest host protection level.
I guess you want a way to make this code run no matter if a abort is called rigth? - Well you can't sorry (you can handle the ThreadAbortedException but only to die gracefully)
|
|
|
|
|
Hmm... let mi ask this simple question - so what exactly critical regions do? They warn CLR. So what? What does it warning do?
modified on Wednesday, February 13, 2008 9:23 AM
|
|
|
|
|
Hey guyz
Im having a problem with a userControll im writing. Basicly its a label that changes color based on the "status" of it red, yello or green. and then i use that to disply errors and general info like "Enter User Details Here"
Now on some of the forms of my app the posible error messages is longer than the form itself for example "Database Connection No Longer Avalibal > Transaction Terminated". So when i got at work this morning i decided to make the labels text scroll past.
this is the code i have so far (its not my actual controll, its just a test project)
its a form with a label on it
public partial class Form1 : Form
{
char charTemp;
string tempMessage = "";
string message = "";
TimerCallback timeCB;
System.Threading.Timer timer;
public Form1()
{
InitializeComponent();
}
public void scrollText(object state)
{
message = label1.Text;
charTemp = message[0];
for (int i = 0; i < message.Length - 1; i++)
{
tempMessage += message[i + 1];
}
tempMessage += charTemp;
label1.Text = tempMessage;
tempMessage = "";
}
private void Form1_Shown(object sender, EventArgs e)
{
timeCB = new TimerCallback(scrollText);
timer = new System.Threading.Timer(timeCB, null, 0, 1000);
}
}
now the obvios error i get is "Cross-thread operation not valid". But there must be a way to update the labels text after the 2nd thread runs its method
any ideas on how i can get it working?
Thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
|
hey
i just read thru that... i dont quite understand it tho?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
|
It boils down to this: Don't update controls from any thread other than the thread that created them. You're breaking this rule by creating a new thread (timer ) and then manipulating a control from that (label1.Text ). As suggested you can use Control.Invoke to fix the problem or, and that would be my suggestion, use a System.Windows.Forms.Timer instead, which fires the Tick on the main UI thread.
Standards are great! Everybody should have one!
|
|
|
|
|
but then the user wouldnt be able to actually fill out the form? the method that scrolls the text is in an infanate loop so to speak...
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
Nope it's not, I don't see any while(true) loop in it. It executes once a second and then the thread returns to any other tasks it might have. Since it doesn't do much work the user won't notice it's on the same thread as the ui. If it was, you could use a BackgroundWorker to do all non UI related work, then use the BackgroundWorker 's ReportProgress method to do any UI updates.
Standards are great! Everybody should have one!
|
|
|
|
|
ok u might have a point there!
so how would i go about using the UI thread to execute ScrollText() once a second?
Thanx
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
think BIG and kick ASS
|
|
|
|
|
|
Here is an example of how to use Invoke .
Put this at the top of your form or class.
<code> delegate void SetTextCallback(string text);
private void SetInfo(string text)
{
if (this.txtInfo.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetInfo);
this.Invoke(d, new object[] { text });
}
else
{
this.txtInfo.Text = text;
}
}</code>
Within your thread to set txtInfo.Text do this:
SetInfo("Hello World");
You always pass failure on the way to success.
|
|
|
|
|
I'm like everyone else here. I want the benefits of the Binary Serializer but I want the human readability that XML / Soap gives you.
Binary Serilization: Almost perfect except its not Human readable.
Soap Serialization: Doesn't work on Generics in .net 2.0 And/OR doesn't serialize private memeber but only properties (useless)
XML Serializer: Flatout Useless. Only serializates public members. Requires huge amounts of markup.
What I need is a serializer that
1) Saves the private/public members (like the binary formatter) (Not the properties which is pointless)
2) It needs to perform deep serialization (like the Bin Formatter)
3) It needs to be human readable.
4) It sholdn't require explicite markup of every member (like XML requires).
MY GOD. Is there not an xml/ soap serializer that is functionaly equivalent to the Binary Serializer available?
|
|
|
|
|
Well you can take your reflection knowledge and write one yourself (it's not that difficult).
Or you can sit down and think for a while why Soap and XML-serializers don't behave the way you want them to.
Let me put it this way: Binary Ser. was build for .net purposes and your class definition etc. are serialized with it.
SOAP/XML was build to be plattform-independend. So you should make sure that everyone understands your data!
|
|
|
|