|
I really wrote my exe file and the database to a DVD and it worked without any problem.
Maybe the ldb temporary file is not required?
Please advise.
|
|
|
|
|
AngryC wrote: Maybe the ldb temporary file is not required?
I think this is correct. It is normally used to handle multi user access. If its not there (for example because of readonly media) it *may* be possible that multi user access is somehow unsafe.
|
|
|
|
|
I said floppy!! You could have used a CD too, they're at least a little cheaper!
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I have found a condition where my dialog does not stay modal. I'm using the following snipit of code to create my modal dialog...
public void ShowMyDialogBox()
{
MessageForm testDialog = new MessageForm();
// Show testDialog as a modal dialog and determine if DialogResult = OK.
if (testDialog.ShowDialog(this) != DialogResult.OK)
{
Console.WriteLine("ERROR Broke Modal DialogBox\n");
}
testDialog.Dispose();
}
This method is called when my serial communications callback function gets called. When the message dialog is displayed, I can still click on the parent form to move it around, or perform button click actions.
The only thing I can think of at this point is it might be a threading issue, where the callback is running in a different thread than the main thread.
Can anyone help me?
McSmack
-- modified at 20:59 Wednesday 28th June, 2006
|
|
|
|
|
McSmack,
I would agree with your assessment, that it is a threading issue where the callback is running in a different thread than the main thread. This would cause the two dialogs to act as you mention. Here is a way to test that to see if it is the case, and also a way to fix it if it is.
First, to test if they are running on different threads
1) Add the following line of code to the constructor of your main parent form:
System.Threading.Thread.CurrentThread.Name = "Main Thread"; This will give a name to the main thread so that we can identify it and distinguish it from another thread.
2) Now, inside the dialog which you want to show (the MessageForm dialog), add this line to your function ShowMyDialogBox :
System.Diagnostics.Trace.WriteLine("Thread is named: " + System.Threading.Thread.CurrentThread.Name); This will write a line to the trace output which gives you the name of the thread which is calling ShowDialog on your second form.
Now, look at the trace output (one way is to run the program in debug mode and then look at the output in Visual Studio) and see if you see "Thread is named: Main Thread" when your ShowMyDialogBox function is called. If it is, then the dialog is being displayed on the main thread after all and something else is wrong. If it is not the same thread, then you will see something like "Thread is name: " - just blank, because the thread is unnamed.
Second, marshaling back to the main thread
If the issue is indeed that the second dialog is displayed on a different thread, here is the way you can fix your ShowMyDialogBox function so that you can marshal back to the main thread:
public void ShowMyDialogBox()
{
if(this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(this.ShowMyDialogBox));
return;
}
...
} Basically what this is doing is checking (via InvokeRequired ) whether the thread which is executing the ShowMyDialogBox function is the same thread which created the main form. If it is not, then InvokeRequired will be true, and the function BeginInvoke will post a message which the main thread will receive. The BeginInvoke will cause the main thread to execute the code contained in the method ShowMyDialogBox . Thus, when the main thread is executed the function, InvokeRequired will be false, and the rest of the code will execute as normal, with your second dialog box completely modal.
Let me know if anything in this is unclear or if you are still having problems. I don't pretend to be an expert at this, althought I have dealt with the same kind of problem you are having.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hello Alexander,
Is it also possible to Invoke a Method with Parameters? ShowMyDialogBox(bool btest, ....)
I had some problems compiling this.
Just for Info.
Thanks for your time,
Martin
-- modified at 1:35 Thursday 29th June, 2006
|
|
|
|
|
Martin,
You won't be able to invoke a method with parameters if you are using the MethodInvoker delegate. Here is what MSDN says about MethodInvoker :
"MethodInvoker provides a simple delegate that is used to invoke a method with a void parameter list. This delegate can be used when making calls to a control's invoke method, or when you need a simple delegate but don't want to define one yourself."
Since MethodInvoker has a void parameter list, and since the function you specify must have the same parameters as the delegate in question, you won't be able to invoke a method with parameters using it.
In order to do this, you need to define your own delegate, which has the correct argument list. Let's suppose that the function you want to invoke by BeginInvoke has two parameters, a bool and a String , and that it looks like this:
public void ShowMyDialogBox(bool bTest, String message) Now, you would define your delegate like this:
public delegate void MyDelegate(bool bTest, String message) The name of the delegate is completely optional, as are the names of the parameters. We could have called the boolean parameter anything we want (e.g. bBoolParam ) and we could have called the string parameter anything we want. Now we would invoke this as follows:
BeginInvoke(new MyDelegate(ShowMyDialogBox), new object [] { varToBeParam1, varToBeParam2 }); So now, if we put that together, our ShowMyDialogBox function would look something like this (assuming the scenario which McSmack had laid out):
public void ShowMyDialogBox(bool bTest, String message)
{
if(this.InvokeRequired)
{
this.BeginInvoke(new this.MyDelegate(this.ShowMyDialogBox), new object [] { bTest, message });
return;
}
...
} Hope that helps! Feel free to respond if you have any more questions about this, or if you do not understand something in the answer.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hello Alexander,
Thanks for your help.
<b></b>I think I did everything correct so far.
Here is my code:
private void XXXChanged(object sender, XXXEventArgs e)
{
reaAct = e;
MethodInvoker mi = new MethodInvoker(YYYChanged); <b>//Here is the error point (missing the Argument)</b>
Invoke(mi);
}
private delegate void ActionDelegate(XXXEventArgs e);
private void YYYChanged(XXXEventArgs e)
{
if (InvokeRequired)
{
// We're not in the UI thread, so we need to call BeginInvoke
BeginInvoke(new ActionDelegate(YYYChanged), new object[]{e});
return;
}
...
}
I think I should use the other Constructor of the MethodInvoker, but I don't know how.
Thank's for your time and help.
Martin
-- modified at 12:12 Thursday 29th June, 2006
|
|
|
|
|
Martin,
If you want to pass arguments to the method that you invoke, you cannot use MethodInvoker . The other constructor of MethodInvoker won't help you. The function which you specify with the delegate has to have the same signature as the delegate, and because the MethodInvoker delegate has a void parameter list, the method you invoke with it must also have a void parameter list.
I'm not exactly clear about what your XXXChanged function is supposed to be doing. However, if you want to invoke the YYYChanged function from it and change back to the main thread, then you can do exactly the same thing you did in the YYYChanged function, like this:
private void XXXChanged(object sender, XXEventArgs e)
{
if(InvokeRequired)
{
BeginInvoke(new ActionDelegate(YYYChanged), new object [] { e } );
return;
}
...
} If you do not need to change threads and you want to call the function YYYChanged directly from XXXChanged then I see no reason to use the Invoke function.
Let me know if that helps you out. If not, could you be a little more specific with what you want the XXXChanged function to do?
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hello Alexander,
You got it!
I didn't need the MethodInvoker at all.
Thanks for your help and time again!
Martin
|
|
|
|
|
Thanks for the tremendous help Alexander!
Indeed, my modal dialog was being run in another thread. So after applying your solution
it worked, however, my old thread is still running and executing code as well as the new main thread which is executing the same code. I'm not a thread expert. Is there a way to terminate the old thread after the this.BeginInvoke() is called?
Thanks again for the help.
McSmack
|
|
|
|
|
There is a way to terminate a thread, but it is not generally the best way to deal with a thread which needs to be stopped. The best way is to simply exit out of the function which the thread is processing, which should stop the thread. This may be different, however, depending on how your second thread was created.
So, how is your second thread created? From your first post, it sounds like you are not explicitly creating the thread (with code like Thread myThread = new Thread(new ThreadStart(SomeFunctionToProcess)); ). It sounds rather like a thread is being created by a component you are using and that thread executes the callback code, part of which is calling the ShowMyDialogBox function.
If you do not know how the second thread is being created, try this: inside the callback function (the function which calls the ShowMyDialogBox function) make sure that the function ends after the call to ShowMyDialogBox . Also make sure that after the call to BeginInvoke in the ShowMyDialogBox function you have the return keyword - this will force the secondary thread to quit the ShowMyDialogBox after it tells the main thread to process the function with the BeginInvoke function.
Final question: what is the method signature of your callback function? Specifically, what are the parameters?
If you can get me the answers to these few questions, I should be able to help you out.
Sincerely,
Alexander Wiseman
|
|
|
|
|
Thanks in advance for all your help.
One of the programmers here, created the serial DLL I am using. In that library he has a notify delegate which I subscribe to. His delegate has a couple of parameters which allows me to retrieve the data. Because I deal with a few different communication entities, I created a class which encapsulates the serial DLL, as well as some other specific comm stuff. In my class, I have
// Callback delegate that subscribers must implement
public delegate void DataReceivedHandler();
public event DataReceivedHandler OnDataReceived;
where OnDataReceived gets called inside my subscribed function with the serial library.
Sorry for the longwinded description. So the answer to one of your questions is that
once the library receives data, it creates a "notify" thread and calls my subscribed function which is in my comm class. The code is below
private void SerialConnection_PacketReceived(object sender, ReceivedPacket pkt)
{
// If anyone is subscribed to callback, notify them
if( OnDataReceived != null )
{
m_receivedPacket = pkt;
m_dataSizeReadIn = (int)m_receivedPacket.packet.Length;
Buffer.BlockCopy( m_receivedPacket.packet, 0, m_buffer, 0, m_dataSizeReadIn );
// Call Subscriber
OnDataReceived();
}
}
The serial class (which is also a form) is a member of my main form. The ShowDialogBox() resides in my Main Form. But I could easily move it to serial class. What do you think?
Regards,
McSmack
|
|
|
|
|
McSmack,
Sorry for the late response. I'm not sure I have enough information to accurately answer your question, but let me ask you two things to clarify:
1) What symptoms cause you to think that the secondary thread is still running?
2) How is the thread created in the serial library? If you don't know, could you point me to the place on this site that has the serial library so I can check the code?
I think what may be happening is that your secondary thread is ending, but then more data is sent to the serial port, so your callback function is getting called again and probably causing another dialog box to be displayed. If this is the case, then inside your ShowMyDialogBox function (but after you marshal back to the main thread (i.e. after the InvokeRequired statement) you should check if a dialog box has already been created, and if it has, then do nothing. The best way to do this is to make your secondary dialog variable a member variable of the main form and simply check if the dialog is already created. If it is, don't open another one.
Let me know if that helps point you in the right direction. We should be able to work this out!
Sincerely,
Alexander Wiseman
|
|
|
|
|
Hey Alexander,
Hopefully I can answer these questions to the fullest
1) What symptoms cause you to think that the secondary thread is still running?
I'm most likely wrong, but it seems to be still running. My main form has a TextBox window that gives me updates of where the data control is at, and my ShowMyDialogBox() displays a transparent modal dialog over the main form. When I place the BeginInvoke(new MethodInvoker( this.ShowMyDialogBox)) line in my ShowMyDialogBox() method as you suggested, the dialog comes up and it is modal, but I can still see that the code is still running, displaying me updates in the main form's TextBox.
2) How is the thread created in the serial library? If you don't know, could you point me to the place on this site that has the serial library so I can check the code?
Here are the lines in the library that create the thread..
rcvNotifyThread = new Thread(new ThreadStart(RunRcvNotifyThread));
rcvNotifyThread.Priority = ThreadPriority.Normal;
rcvNotifyThread.Name = "Notify " + portName;
rcvNotifyThread.Start(); // Start the new thread
===========================================================
When you said that the MethodInvoker is just a delegate, it got me thinking. So I played around with it and found a good place to bring the secondary thread back to the main thread. Upon entry of my callback function, I decide to place your solution here since the method that runs all my data processing matches the MethodInvoker delegate. See below
public void ReceiveDataFromSerial(); //Just here to show you the prototype
// the method that implements the delegated funtionality
public void ProcessIncomingData( )
{
string testString = "Thread is named: " + System.Threading.Thread.CurrentThread.Name;
System.Diagnostics.Trace.WriteLine(testString);
Console.WriteLine(testString);
//If not in the main thread, move there and let old thread end
if(this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(this.ReceiveDataFromSerial));
return;
}
// Process Data
ReceiveDataFromSerial(); // This function process all
}
This seems to do the trick. I will keep testing it to make sure everything is sound.
I truly appreciate all your help Alexander.
Regards,
McSmack
|
|
|
|
|
Excellent! I'm glad you got it working.
The purpose of my second question was to make sure that the serial library was explicitly spawning a new thread and not asynchronously invoking a delegate function. I see by the code you put there that it is indeed explicitly creating the thread, so you probably don't want to kill the thread.
I think you solution is perfect, and I understand now why you had said that the thread was still running. Switching to the main thread before doing any of the data processing seems to be the best way to go.
Let me know if you run into any more problems
Sincerely,
Alexander Wiseman
|
|
|
|
|
I'm writing a short little script in Visual Web Developer where you select from a list of sites in a radio button list, then click a "Go there" button and it will take you to the site you have selected.
But for th elife of me I can't figure out what code to put behind the button so that it takes you to the webpage. Here is what I'm working with:
<br />
if (RadioButtonList1.SelectedIndex == 0){<br />
insert code to redirect here<br />
}<br />
In other words, if the first radio button is selected (index 0) then it takes you to a website when the button is clicked.
Thanks ahead of time.
EDIT: I think I'm on right track, but not working...
protected void Button1_Click(object sender, EventArgs e)<br />
{<br />
HtmlLink myHtmlLink = new HtmlLink();<br />
<br />
if (RadioButtonList1.SelectedIndex == 0)<br />
{<br />
myHtmlLink.Href = "www.mywebpage.com"; <br />
}<br />
}
-- modified at 19:23 Wednesday 28th June, 2006
|
|
|
|
|
Arkon948 wrote: I'm writing a short little script in Visual Web Developer
Wrong forum, you posted this in the C# forum, try the Web Development forum for this.
If you were asking for C#, I would say use the WebBrowser.Navigate(URL)[^] method but you didn't ask for C#...
Mike Poz
-- modified at 19:47 Wednesday 28th June, 2006
Wrong MSDN URL...
|
|
|
|
|
Hello everone
I'm about to write an SQL database program, in which I would like to add "Export to" feature, like exporting my data as Excel speardsheets, Access, or even SPSS. I really can't fully describe the idea of integrating all these programs, but I'm sure you got it.
Some points arising
1- Is it legal?? Or do I need the prior permession of SPSS -and other copyights owners- to add "export to SPSS" -or any other program- in my program?? I know this may sound as a ridiculous question, but I don't want to violate any copyrights here.
2- Do I have to write my code from the scratch, or may I use their Dlls -again the copyrights issue-?? If I can't use their DLL, how would I know their format??!
3- I'd like the export ability to work even on machine that doesn't actually have SPSS currently installed on it, also it should be version independent. -ie. I don't want to dynamically link to dlls supposed to be on the target machine. Dlls should be supplied with my program's package-
4- What would be your suggestions of the best way to do it??
5- An example is media players that support RM formats. We all know Real corp. has copyrights over RM. So how would other media players support it??
PS. SPSS is just one example of many programs I'd like to integrate together. Noting that the integration is only in exporting/importing, ie. my program will not open/edit any SPSS files
If you have ANY suggestions, ideas, or comments, I'd really appreciate it.
Thank you.
|
|
|
|
|
The (Open Source) R project contains a library called "foreign" which allows one to read data from a number of proprietary formats in common statistical usage, including SPSS files.
Read the following for details:
http://cran.r-project.org/doc/manuals/R-data.pdf
Examining the R code (written in C) will therefore help you understand the structure of the .sps file type.
Good Luck!
|
|
|
|
|
Hello and thank you for replying.
I've taken a quick glance at the pdf you kindly provided -and it was interesting I must say-, yet as I said before I'm quite concerned about copyrights of the SPSS, or anyother formats I'm going to import/export. the R team didn't do it at a commercial scale, unlike me. So any idea about the legitimacy of this action -on a commercial scale-?
And again, thank you for helping me with the SPSS format. It was my biggest problem.
|
|
|
|
|
The javascript code in the JS file residing in the wwwroot folder does not execute on postback. If I refresh the page it executes otherwise it does not.
Any helpful hints? I am using C# as the code behind scenes.
thanks
Naji
|
|
|
|
|
Do you include the Javascript file in the page?
Does the code contain any code that is not in functions, so that it would do anything without calling functions?
What has made you think that the code doesn't execute?
---
b { font-weight: normal; }
|
|
|
|
|
I have the src attribute that references the javascript file.The javascript file contains a bunch of functions. The show menu function works when the page is loaded but when I press a button on the page it does not work anymore unless I refresh. I am just concluding that the javascript file is not being seen and executed on postback, but I am not sure.
-- modified at 21:47 Wednesday 28th June, 2006
|
|
|
|
|
It's much more likely that there is something in the page that breaks the Javascript.
Have you enabled Javasript error messages in the browser?
---
b { font-weight: normal; }
|
|
|
|
|