|
Actually, it's all running on the same thread. What does volatile do for me ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
What timer call are you using?
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
I'm just creating a timer - do they automatically run on another thread?
private Timer timer = new Timer();
in the constructor....
timer.Interval = 100; // poll 10 times a second
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
http://msdn.microsoft.com/msdnmag/issues/04/02/TimersinNET/default.aspx[^]
The key here is that some timers can get pre-empted or simply "stop" running depending on the class you use. The windows forms timers can be really quirky.
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
Cool - thanks for the info.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
The timer callbacks occur on another thread, unless you're using the Windows Forms timer, in which case, the callback/event will occur on the UI thread. So you do have two threads, my guess is that you are accessing a shared variable without locking (may not be needed) and without declaring it volatile.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
S. Senthil Kumar wrote:
unless you're using the Windows Forms timer
Which I thought I was.
S. Senthil Kumar wrote:
my guess is that you are accessing a shared variable
OK - I'll look into that, thanks for the help.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Was the UI responsive when the timers stopped working? Maybe the message pump got blocked and the timer messages didn't get processed at all?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The UI stays responsive, and it's consistent in it's demands, it would have been using another timer to display static images, and allowing browsing of a song list that no-one could access because they coin mechanism didn't respond to having money put in it.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hi
im using MS access as my database... i've to receive data from another computer and store the data in my database... initially, both computers were using string for read and write... my computer would get the data and store them in a text file... but as the data will keep on increasing and it is a huge amount, as well as for better layout, my computer will now use database to store data instead of in a text file>notepad...
the codes used in the other computer is in string and i will NOT be changing the codes in that computer..
im not sure how a computer using string to read and write data will be able to pass data successfully to a computer using varchar for database.. i know i can use a wizard to convert data in text file to table form in database..
but what i want to do is to pass the data directly into a database from the other computer without having the user to need to use a wizard..
the user is supposed to click on a button in a form in my computer and the data will be retrieved from database for user to view/update...
my question is: how do i write/change my codes in MY computer in order for the data passed over to directly be stored in a database? (the data will not be kept in text file any more..)
thanks a lot!
|
|
|
|
|
nidhelp wrote:
im not sure how a computer using string to read and write data will be able to pass data successfully to a computer using varchar for database..
Make sure your varchar is as long as the longest possible string you'd pass in. That's it.
nidhelp wrote:
but what i want to do is to pass the data directly into a database from the other computer without having the user to need to use a wizard..
Do you know any SQL ? What you're after is a simple INSERT.
nidhelp wrote:
my question is: how do i write/change my codes in MY computer in order for the data passed over to directly be stored in a database? (the data will not be kept in text file any more..)
Connect to a database with a table that has a varchar value, and do an INSERT into it. Do you intend on making this data easy to search in any way ? Will you at least put a datastamp on it ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Well, my DLLs remain locked by my application even after I do an AppDomain.Unload(). I haven't investigated deeper but I was hoping there's someone who has ran across this before. I'm quite sure the assemblies cannot be loaded in any other appdomains, so... meh.
Since it's too late for coding here, I'll see tomorrow whether the AppDomain really unloads or if it goes funky...
|
|
|
|
|
Are you unloading an AppDomain that you created on your own? If so, are you sure you didn't access any type from any assembly in that AppDomain?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Yeah, I created it. Well, I create a few objects and use them via a proxy (AppDomain.CreateInstance()) but that shouldn't matter, right?
|
|
|
|
|
I haven't used AppDomain.CreateInstance, but MSDN has this to say
"when this method attempts to return the Assembly for the loaded assembly to the current application domain, the common language runtime will try to load the assembly into the current application domain "
That is pretty suspicious..
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Aha! Yeah, I'd better investigate that. Thanks for the tip
|
|
|
|
|
|
Alrighty, I'll check it out! Thanks for the info.
|
|
|
|
|
Hello,
I have developed a .NET application for three years. This application
builds several types of objects, and serialize them with the Binary formatter.
Everything has been fine, until...
Now, I need to build another application, independant from the first
one, that needs to access some of the serialized objects built with the first application.
Apparently, even though I define my objects with the same structure (even
the same source!), the 2nd application's deserializer refuses to load the objects:
.NET is looking for the assembly of the *original* application.
Therefore I rewrote the first application, with a DLL responsible for these
objects processing, including their serialization/deserialization. I was hoping that this
DLL, if shared by the two applications, would accept in both cases to load & save these
objects (because it would be the same assembly, right?).
But this DLL, when run by the two applications (even the first one), refuses to
deserialize anything (I guess the new version of my first application has not the
same "assembly" as when it did not have the DLL...)
Is there any way to tell .NET that another application needs to access the data?
I cannot believe that the serialization/deserialization system would not allow
two independant applications to share data stored in a file...
Any help would be welcome!
Max Silberztein
(please cc your answer to msilberz@univ-fcomte.fr)
|
|
|
|
|
You can deserialize to a type other than the original by assigning an instance of a class which inherits from SerializationBinder[^] to the BinaryFormatter 's Binder property.
You only need to override the BindToType method and return the type of the object you'd like to instantiate.
The simplest case would be:
public class Binder : SerialiationBinder
{
public Binder(){}
public Type BindToType(string assembly, string type)
{
return typeof(WhateverClassYouAreTryingToDeserializeAs);
}
}
BinaryFormatter formatter = new BinaryFormatter();
formatter.Binder = new Binder();
WhateverClassYouAreTryingToDeserializeAs wcyattda = (WhateverClassYouAreTryingToDeserializeAs)formatter.Deserialize(stream);
Charlie
if(!curlies){ return; }
|
|
|
|
|
Charlie Thanks for your help!
(1) When I use the method:
public Type BindToType (string assemblyName,string typeName)
{
return typeof (Grammar);
}
I get the exception message:
Possible Version mismatch. Type Nooj.Grammar has 36 members, number of members deserializes is 1.
but I have not changed anything in the definition of "Grammar"! There were
36 members, and they all are still there...
(2) If I use another version of the method (got from MSDN):
public Type BindToType (string assemblyName,string typeName)
{
Type typeToDeserialize = Type.GetType (String.Format("{0}, {1}", "Grammar", assemblyName));
return typeToDeserialize;
}
I then get the Exception message:
Type is not resolved for member Nooj.Grammar, Nooj, Version=1.0.1916.21705, Culture=neutral, PublicKeyToken=null.
(3) I noticed in MSDN that their new Version2Type (i.e. my "new" Grammar type) follows the interface "ISerializable". Therefore I tried to implement it (without the [] otherwiser it does not compile):
void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("x", x);
info.AddValue("y", y);
// ... all the 36 fields
}
as well as:
private Grammar (SerializationInfo info, StreamingContext context)
{
x = info.GetInt32("x");
y = info.GetInt32("y");
// ... this would not be feasible because some of the fields are complex recursive objects...
}
but then I got the exception message:
Exception has been thrown by the target of an invocation
Any idea?
--Max
|
|
|
|
|
I finally found out the solution: because my object Nooj.Grammar contains
fields that are other objects, I need to make sure BindToType returns
each correct type (rather than just Nooj.Grammar).
public Type BindToType (string assemblyName,string typeName)
{
if (typeName == "Nooj.Grammar") return typeof (Grammar);
else if (typeName == "Nooj.GramType") return typeof (GramType);
else if (typeName == "Nooj.Graph") return typeof (Graph);
...
else return Type.GetType (typeName);
}
--Max
|
|
|
|
|
Does anyone know how to intercept the Paste operation (on ctrl+V) in a RichTextBox?
It appears that the RichTextBox is different from a TextBox in this way.
public override void WndProc(ref Message m)
{
if(m.Msg == 0x0302)
MessageBox.Show("Paste");
base.WndProc(ref m);
}
This chunk only works when you call the Paste() method directly. It does not work on Ctrl+V or Ctrl+Insert.
|
|
|
|
|
Well this is an answer without checking anything:
I would catch the key input (keydown event), check if you the user typed ctrl+v and then paste.
|
|
|
|
|
You can use Key Down event
private void richTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.Control && e.KeyCode==Keys.V)
{
}
}
You can get and Set data using Clipboard class
MCAD
|
|
|
|