My program moves files from one folder to another immediately upon creation. The files will be coming in by about 50 per second. The program monitors two folders and sends files in those two folders to certain directories on the computer.
The one thing I want to get sorted out is the errors that could potentially pop up. I thought about using messagebox.show to let the user know lets say "the folder does not exist," but with 10000 or so files unable to be moved, or if access to directories is denied, the computer might just run out of memory with 10000 popups.
An alternative is simply to display a message to the user on the GUI control, and stop the file watcher. The problem is, my folderwatcher class cannot access the status bar in my GUI. So if the status bar was called messages, I cannot simply assign "messages.text" to the error message from the exception thrown in the folderwatcher class.
I was also told that it is bad practice to give the control on the GUI to the folderwatcher class as it defeats the purpose of object oriented programming. (something along those lines).
So, I thought about constructing a class that simply stores data/status messages. My GUI will hook in to that class and the folderwatcher class will update it when an error occurs. When that happens, my GUI will update and the messages.text will show the error for the user to see.
I think this concept will work quite well, but I'm not sure where to start. If you need any additional information I'll be happy to provide, but feedback and hints/tips are what I'm looking for.
Also, is my method of constructing a separate class holding information the best method to transferr error messages between the class and GUI? or is there an easier way to do it?
Sincerely,
tf.rz. Thanks for your help! It is greatly appreciated.
Build a private method with strings with different values and when an Error Pops, Just Get and Set the Value to the Appropriate Messagebox. Which could be assigned as a global variable.
I've hooked the class and the GUI via another class which contains just one string and an event handler. The GUI subscribes to the event handler and the class will create an instance of the new class created and modify the string. When the string changes, the GUI will be updated and the user will then see the message. Thank you to all who contributed!
Related
I have a console application which continuously receives messages and saves those messages to a database. And I have another project which has a method that takes a message and checks if this message contains certain information. Now I want use a delegate to create a pointer for the check method and pass this pointer to the console application. Both projects are in the same solution. How can I do that?
You probably can't, because it sounds like from your description that the two programs are running in separate processes. Perhaps you could watch for new messages to your database, or set up a pipe between the two. In order to use a delegate your programs would need to be in the same process space.
If I have mis-read your post and one project is an exe and the other a dependent dll, then you can do what you are thinking. You can search for "C# event delegate examples". If you have a problem post some example code.
I'm currently working on a project to provide interop between two unrelated pieces of software. I need to pass the data from a textBox/textBoxes, into a textBox of the other said app.
My current idea is to find the handle of the target control, make it active, and enter the data by copying it to the clipboard, and pasting it via:
Clipboard.SetText(textBox1.Text, TextDataFormat.Text);
SendKeys.SendWait("^V");
As textBoxes have no 'caption', handles are dynamically assigned on the process start, and class names are appended with various data regarding the process, is it possible to get a handle for an object within a window via some sort of indexing? I'd be more than willing to find the correct handle by trial and error if need be, as long as it would be consistent for every instance of the application.
Thanks in advance
A.
If you don't have any other choice.. to make this easier, you can use AutoIT.. I had to do something like this a very long time ago. AutoIT. They have a DLL for .net Applications, so you can use their functionality without having to use their scripts. If you do use their scripts.. they also have an option that will turn their script into an executable.
If an error occurrs, a log file,in "pure text" format will be created to then be sent by another application, the errorReportin.exe. That's a GUI application that will read and by using BackgroundWorker sent the file contents to my e-mail.
1-question: Do I need really to use some XML or JSON etc instead of simple text file? why? will I have some kind of problem by using this? I can't think one reason for don't use simple text file. It's easy to read, maybe by reading the e-mail only I can have a idea either solve the probrem.
2-question: Is dangerous make this file readable to anyone? do I need encrypt it or something like?
Until now, I'm loging StackTrace and Message from Exception and Date. Say if you think that I'm missing some information to do log.
Use whatever file format makes sense for your application. XML and JSON are useful if you're conveying information with a number of different fields, but if it's a simple message then plain text is perfectly fine. In fact many applications pass simple text messages for inter-process communication.
This depends on the sensitivity of your data and whether it's exposed on the public internet. If the answer to both is yes, you should take steps to ensure the transport and/or message are protected.
Stacktrace is frowned upon in some places and others dump it into the log anyway. I don't see any reason why a simple log needs to be made complicated. Your application would then need to build XML etc.
Also why do you pass the log to a secondary process? Can the main application not just have a class (on a separate thread if need be) that waits on messages and logs them?
I have essentially two programs:
main.exe
update.exe
Update creates a flag file (update.inprogress) so that main cannot run while the update is in progress.
If main opens and that file exists, it immediately exits to prevent a program in use conflict.
I'm only having one issue. If the update is in process, the main program closes without and reason when they try to go in. I need to tell them the program is updating to keep them from calling us that the world has come to an end...
My question is, how can I issue a message that the update is in progress without tying up the main.exe? If I issue it from main.exe, then it will be in use and cannot be updated.
I was thinking of opening up notepad and putting a message in there but that just seems like a bad way of doing it.
I could also create another exe that only displays this message, but, if I have to update it, it will be in use too.. kind of defeats my purpose.
Anyone have a better idea?
Clarification:
This is a peer-to-peer network. The update could be run on workstation XYZ and someone could attempt to get into the main.exe at workstation ABC. This is why I am using a flag file. I have to way to check the process running on another workstation.
I assume that when update.exe runs, it does not need to update itself? If that is the case, you can modify update.exe to invoke main.exe if no updates are necessary.
For instance, if an update is necessary(you can accomplish this via a adding a version number to your main.exe and checking it), update.exe will create your update.inprogress file and run the updates. Then if another instance of update.exe runs, it will see the update.inprogress file and alert the user that update is in progress and terminate itself without tying up main.exe. If update.exe runs when no updates are necessary and update.inprogress does not exist, it will invoke main.exe programmatically.
I would suggest to create a thread from your update.exe to check for the existence of your main.exe process. In case it shows up, alert the user with a message from your update.exe.
I have a C# solution which contains a project and a class library written by somebody else. The class library gets GPS data via wifi. The project shows the processed data on a map. Now, I want to see the contents of some variables in the class library in real time for the sake of debugging.
I tried to use
System.Diagnostics.Debug.Write(value)
without success. It seems it does not do anything.
Also I tried "MessageBox.Show(value.ToString())" which was good but it stopped the wifi reading and interrupted the program as I needed to press OK button each time that it showed up.
Moreover, I added a windows form (which contained a textBox) to the class library to print the data in the textBox, however, when I wrote:
Form1.textBox1.Text = value.ToString()
It gives me this error:
Error 3 'MapNMEA.Form1.textBox1' is inaccessible due to its protection level C:\Users\john\Documents\Visual Studio 2010\Projects\new ver of map purecom\MapExplorer\MapExplorer\MapNMEA\MapNMEA\SerialPort.cs 184 27 MapNMEA
"MapNMEA" is the name of the class library. Also "MapExplorer" is the name of both solution and the project. "SerialPort.cs" is a file inside the class library in which I wrote the above code.
My question is how to show the content of those variable (they are 3,4 variables) in real time and this act should not stop the wifi reading. I need to do this as an electrician who does not know much about programming wants to check whether a GPS device sends the data to my computer correctly or not.
UPDATE 1: Actually I noticed that System.Diagnostics.Debug.Write(value) is working but as there was too many warning messages showing up in the debug window, I did not noticed it. Now, if somehow I could remove (or hide) other (warning) messages, I would see only my desired output. Do you know?
Debug.Write should be fine if you attach a listener first (Debug.Listeners.Add( new _a_listener_type() )).
Also, you should probably be aware of the AutoFlush property on the Debug class which determines whether or not Flush is automatically called.
Debug.Write should work - by default it will write to the 'Debug' window in Visual Studio if you have the debugger attached. Are you sure you're looking in the right place?
If you want to use the form approach, you need to keep track of the instance of the form which is open, and give it a public method. For example:
public void WriteDebug(string message) {
TextBox1.Text += message + Environment.NewLine;
}
Then you can call formInstance.WriteDebug(message);.
Do you run debug build? Also your code with textbox does not work, because textBox1 is non-public
I think you may not be searching the right location: Is there something preventing you from debugging on a PC first before going to a target? If not, the you should probably use the traditional way: put spies on variables, use your IDE (Visual Studio) to watch them and so on.
If you actually NEED to run on target without advanced debug tools, then you might want to take a look at some easier solutions:
log them to a text file (append or replace, whatever you need), then have a viewer opened at hand
make another non-modal form with a textbox, and call a form2.writeDbgTextBox(String) every time you need to refresh
Be sure to remove this code on release (eg. by putting them in a #if DEBUG section)
And whatever happens, DO NOT try to write to an existing Message box! they are made to pop up and close, not to interact with your code.