|
As Luc says, it's not so much the treading at fault as how you do the graphics.
Moth balls clear the label to white after painting themselves - so depending on the exact timing, you might be left with a white screen for longer than you anticipate - hence the flickering.
e.g.
Ball 1 draws itself and waits 100ms before blanking the background. Meanwhile Ball 2 is drawing itself - if it has just finished drawing ball 2 when ball 1 clears the screen, then it's only visible for a short time.
I haven't read the article to which Luc referred - but I think you should rethink how you're doing this entirely (of course, if you're just playing with threads, then the graphics doesn't matter).
The way I tend to do it is to keep track of the time, and the velocity of my object(s). Then the object calculates where it needs to be drawn depending on what time it is now.
Loop
ForEach(Ball ball in Balls)
{
}
DrawTheBackground();
ForEach(Ball ball in Balls)
{
}
End Loop
Now you could also think about double or triple buffering (which may improve matters, but the above will get you what I think you want better than using individual threads for each object.
You can also do it with threads, of course - but I would suggest updating the object's position in a thread - and keep a separate process to draw everything.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I have designed a C# program in VS2008 (.NET 3.5). the purpose of the program is to use my brokerage's COM dll components to connect to them and pull quote history automatically every so often for analysis in my other program which emails me updates and possible trade decisions.
my program works just fine but the issue is knowing when to register the DLL's or not. What I mean is that if the user has the brokerage's software already installed on the machine then there is no need to register them. in fact, doing so will work temporarily but if my program is uninstalled them the brokerage software doesn't work. i had to uninstall, reinstall, and reboot before the brokerage software would work after registering "my" DLL's.
i am using a batch file script to execute regsvr32 commands on the DLL's in my program's installation directory and what i believe what is happening is that there is only one entry in the registry for a given CLSID and therefor, when my program is installed and runs for the first time it registers the ones in my directory. then if i uninstall mine, the entries are gone or invalid and the brokerage software cannot load the objects because the CLSID entry in the registry is either missing or points to a file that no longer exists.
how would i go about ensuring that my program does not screw up the brokerage software while still working on machines that don't have it installed? is there a way to use the COM DLL's in my directory WITHOUT having them registered with the system? that would solve the problem. if not, how would i go about this? would i have to write code to check the registry for valid entries for each CLSID and if it does not exist, then register that DLL?
Thanks in advance,
-Ryan
|
|
|
|
|
|
you are correct. i did a little digging around as well as some trial and error and i came to the same conclusion - COM components must be registered with the system (with the exception you found).
the 4 main COM DLL's need to be registered but the dependencies that they use only need to be in the same directory as the calling COM DLL. i don't need to register those other ones.
now that i know this, i can figure out how to proceed. what it looks like i need to do is write some code to check the registry to see if there is an entry for the CLSID and ProgID for each of the 4 main components and if they exist and link to a valid, existing file then i would not register the DLL. otherwise, i would register that DLL.
that should ensure that if the brokerage software is already installed that my software doesn't screw it up like it did before. plus, it's just extra work and toying with the registry unnecessarily.
however, that link you sent seems very interesting. someone said to me, "In most cases we don't need to register DLLs, if it correctly referenced to your project." this link must be the technique that he was referring to.
i'm going to see if i can use that method instead.
thanks,
-Ryan
|
|
|
|
|
I need to send some io stream ( the io information can be text or video stream ) to some of the existing USB connectors.
I don't know how can i send this stream directly to this port - and if this actually possible.
Someone can help me ?
Thanks
|
|
|
|
|
USB is not a port in the sense that a Parallel or a Serial port is. USB is a BUS, not unlike the slots inside your machine that you plug cards into.
You don't send a stream of data to a USB port. You send it to the device attached. How you do that depends on the device.
|
|
|
|
|
Thanks,
And if i want to send the data like sending to Serial port ? I mean sending data like USB Virtual Com port - is it possible to send it directly to specific port ? if 'yes' so how can i to it ?
|
|
|
|
|
You don't send a stream of data to a USB port. You send it to the device attached. How you do that depends on the device.
What device are you trying to send data to? Is it a flash drive?
|
|
|
|
|
Again, you do NOT send data to a USB port. If you've got a USB Serial Port device attached to it, then you send data to it using normal serial port I/O functions addressing the COMx port that the device is "attached" to. This is no different than if the device was physically attached to a real serial port.
|
|
|
|
|
Hi all,
I have created a ServiceReference (to a JAVA Web-Service) using WSDL.exe. It created a .cs file. I have added this file into my project and using it. No problem up till this point. But I want to know all the APIs exposed from that JAVA Web-Service. How can I do it programmatically and at run time (Using c#)? Please help.
Thanks and Regards
|
|
|
|
|
It seems to me that once you hit that service using the tool it should be providing you with a list of all the available web enabled services that you can access.
|
|
|
|
|
Hi,
I have a DataGridView control on a form. It as one DataGridViewComboBoxColumn column. DataGridView control is not bound to any datatable or collection. I am populating it manually. Suppose DataGridViewComboBoxColumn has items 'CCW' and 'CW'. User can select either of these. While closing the form I am just reading the column values. So for its fine till MultiSelect is set to False.
I want to change DataGrid's behavior to multi select row. User can select multiple rows and change the property to 'CW' or 'CCW' and it should get applicable to all the selected rows in the grid.
How I can achieve it?
|
|
|
|
|
Hello,
I want to run a Command from command promt and want its output and maipulate its output. If required, want to close the process and display error or appropriate message.
How is that possible. Any help is highly appreciated. I am stuck with this and would be glad if any body helps me solve my problem.
Thanks
Thanks & Regards,
|
|
|
|
|
Send the output to a file and retrieve and process it from there. However, your exact requirements in the above question are a little unclear.
I must get a clever new signature for 2011.
|
|
|
|
|
I am tying to connect to server via cmd. Server keeps on giving output. Suppose the server gave output as : Trying to start ..... Cananot load file ..... Exiting OR
Trying to start ..... Authenticating... Some thing ..... More.... Else,.......... keeps on going
While retrieving the output, I want to check for lines like "Cannot find file", "Connected Successfully, etc and set properties ccordingly (like connected = true, errorMsg = "Cannot find file". Where I am calling the class, I can take care of those proeprties and stop if found connected == true or errorMsg.length > 0. With this inform the user that "Connection is achieved or error msg stating regarding "Cannot load file" and disconnect the server if errorMsg found.
try
{
process = Process.Start(processInfo);
process.BeginOutputReadLine();
I start the process, now got to <b>check the output while the process is already running</b>. That checking part am stuck up with. Process mostly wont Exit normally, I got to exit it. I mean just dir and got results ans process is exited - nothing like that. command keeps on giving output lines. To stop the server, I got to press "F4" on command prompt. How do I stop from here.
Thanks & Regards,
|
|
|
|
|
As Richard said, you can direct the output of any command to output file.
e.g.
dir >> C:\\list.txt
this will output all the directories in the current drive to C:\\list.txt file.
Hope this helps.
All the best.
|
|
|
|
|
If you are starting the process from a C# app, then you could use the Process.StandardOutput[^] property to capture the command output and do what you like with it. There is an example in the link.
The other option is to start the command in a command prompt and pipe it's output to your app. That would work with a console app, but I've never needed to try it with a WinForms.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Thanks OriginalGriff,
I coded the foloowing :
<code>
processInfo = new ProcessStartInfo("cmd.exe", "/C " + command);
sb = new StringBuilder();
processInfo.UseShellExecute = false;
processInfo.RedirectStandardOutput = true;
processInfo.CreateNoWindow = true;
process = Process.Start(processInfo);
process.BeginOutputReadLine();
process.OutputDataReceived += new DataReceivedEventHandler(Process_OutputDataReceived);
public string ErrorMessage
{
get { return errorMsg; }
set { errorMsg = value; }
}
private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
errorMsg = "";
connected = false;
string d = e.Data;
if (!string.IsNullOrEmpty(d))
{
if (sb != null)
sb.Append(d + "\n");
Console.WriteLine("LINE = " + d); // I see each line
if (d.IndexOf("Initialization Completed") > 0)
{
connected = true;
Console.WriteLine("********* Connected = " + connected);
}
else if (isInValidLine(d))
{
//throw new Exception(d);
connected = false;
errorMsg = d;
return;
}
}
}
private bool isInValidLine(string line)
{
if (line.IndexOf("Cannot load file") > 0)
{
errorMsg = line;
return true;
}
return false;
}
</code>
The output that I see is :
LINE = Thu Feb 03 17:22:28 2011 Cannot load file path (null) (SSL_CTX_load_verify_locations): error:02001002:system library:fopen:No such file or directory: error:2006D080:BIO routines:BIO_new_file:no such file: error:0B084002:
Based on the above code and output, isInValidLine() should find the text "Cannot load file" and errorMsg should be set to the line and it should return true.
My Implementation :
<pre>
while (!oc.Connected)
{
timepassed = (int)(DateTime.Now - start).TotalMilliseconds;
if (timepassed > timeout)
{
oc.DisconnectServer();
connectedToVpn = false;
throw new Exception("NotConnectedException");
} else if (oc.ErrorMessage.Length > 0)
{
oc.DisconnectServer();
connectedToVpn = false;
throw new Exception(oc.ErrorMessage);
}
Thread.Sleep(100);
}
</pre>
checks for if (oc.ErrorMessage.Length &gt; 0), but the value of errorMsg is always "". Why so ?
Where am I going wrong or doing something invalid that the code seems to never check for isInvalid() method only ? I tried adding the same lines of isinvalid() in the place it is called, but yet no differnce.
Where am I going wrong that the Process_OutputDataReceived never sets and errorMsg via isInvalid() ? Please help me get my mistake and rectify it. Badly stuck up at this location.
Thanks & Regards,
|
|
|
|
|
I can't see anything too obvious with the code as it stands (but remmebr to check the "use HTML in this post" option at the bottom, and use "code block" rather than "inline code" next time).
If you are getting the line printed - and it appears you are - then it isn't obvious what is happening.
Have you tried putting a breakpoint at the start of Process_OutputDataReceived and stepping through?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
Hmm, the class that handles the conection is in a library. When i added break in Process_OutputDataReceived (before execution & while execution), the app doesn't print any Line on Console. I removed the break and tried again then it showed the LINE = on console.
How to add breakpoint in a library class whose dll is included in main project. While degbuging the dll class comes normally and does the debugging.
How to handle this ? Is it due to the class is in a library ?
Thanks & Regards,
|
|
|
|
|
All Time Programming wrote: When i added break in Process_OutputDataReceived (before execution & while execution), the app doesn't print any Line on Console. I removed the break and tried again then it showed the LINE = on console.
That implies it hit the breakpoint - did you try switching to VS and looking at the library code where you put the BP?
I tried your code on my machine - using "dir" as the command, and a file size and date for the comparison - and it worked fine. You need to look at the data you are comparing against, I think: are those really spaces for example?
Or: are you using the release version of the library in the app, and modifying the debug version?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
>> Or: are you using the release version of the library in the app, and modifying the debug version?
What do you mean ? I change the code in library and build it. The reference is added in main application. I build the main app, which updates the dll file and I execute the application. I checked the dll file date/time in main app, its of Release version of library. The library & app is in Release version.
Should they be in Debug version ? How to change them ?
The spacing must not be a problem as I copy from the output only and put in my if to look for indexOf.
But yes, I think that applying BP on 1st line of Process_OutputDataReceived while execution helps. It got the "Cannot load file..." line and it went in isInvalid, went inside that if, changed "connected = false", and for the next line
else if (isInValidLine(d))
{
connected = false;
errorMsg = d;
return;
}
private bool isInValidLine(string line)
{
if (line.IndexOf("Cannot load CA certificate file") > 0)
{
errorMsg = line;
return true;
}
return false;
}
i GUESS i GOT TO debug more carefully. AND should I remove & add refernce everytime I buid the library ?
Thanks & Regards,
|
|
|
|
|
If your library is part of the same solution as your app, then they will both be Release or Debug together: Normally I have separate solutions, and issue the release version of a library for apps to use, while I continue changes in the debug version. In your case, that doesn't apply!
If you mean that errorMsg remained empty after executing the code, could it be that the next line to be received (whether it is blank or not) starts off by setting errorMsg = ""; perhaps? Move your Console.WriteLine to immediately before the first if and see what happens.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|
|
 Both are of different solutions.
But yes, realized during debugging & removed the errorMsg = "" & connected = false lines. And now I see that errorMsg has value in it.
Implementaion PART :
try
{
StartConnect();
}
catch (ThreadAbortException te)
{
Console.WriteLine("Abort Exception CAUGHT");
}
catch (Exception ex)
{
string msg = ex.Message;
if (msg.Equals("NotConnectedException"))
MessageBox.Show("Error connecting to the Server : Connection Time Out \n Unable to connect to the Server", "Time Out", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else if (msg.IndexOf("Cannot load CA certificate file") > 0)
MessageBox.Show("Error connecting to the Server : Problem with Certificate File \n Unable to Load or Find required Certificate file.", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else if (msg.IndexOf("Error opening 'Auth' auth file:") > 0)
MessageBox.Show("Error connecting to the Server : Problem with Authentication File \n Unable to Load or Find required Authentication file.", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else if (msg.IndexOf("Error opening configuration file:") > 0)
MessageBox.Show("Error connecting to the Server : Problem with Configuration File \n Unable to find required Configuration file.", "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
else
MessageBox.Show("Error connecting to the Server : \n " + msg, "Failed to Connect", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
finally
{
}
Console.WriteLine("Execution Completed ");
private void StartConnect()
{
DateTime start = DateTime.Now;
int timeout = 100000, timepassed = 0;
oc = new OpenConnect(cmd, timeout);
int retVal = oc.ConnectToServer();
while (!oc.Connected)
{
timepassed = (int)(DateTime.Now - start).TotalMilliseconds;
if (timepassed > timeout)
{
oc.DisconnectServer();
connectedToVpn = false;
throw new Exception("NotConnectedException");
} else if (oc.ErrorMessage.Length > 0)
{
Console.WriteLine("ERROR MESAGE = " + oc.ErrorMessage);
oc.DisconnectServer();
Console.WriteLine("DISCONNECTED");
connectedToVpn = false;
throw new Exception(oc.ErrorMessage);
Console.WriteLine("THROWN");
}
Thread.Sleep(100);
}
return;
}
iT THROWS "NotConnectedException" exception when the time is over.
The OUTPUT :
LINE = Thu Feb 03 19:07:10 2011 Cannot load CA certificate file........
ERROR MESAGE = Thu Feb 03 19:07:10 2011 Cannot load CA certificate file ......
LINE = Thu Feb 03 19:07:10 2011 Exiting
DISCONNECTED
/// SEE MSGBOX OF TIME OUT I.E. OF NotConnectedException
Execution Completed
Why it doesn't throw that exception of error message ?
I ran without debugging also, increased the timeout duration, yet it waits hlds itself and throws Time out Exception only.
What can be the problem for this ?
Thanks & Regards,
|
|
|
|
|
Reply: it is.
If it wasn't, then your output would contain the line: "THROWN" from the following statement.
Best guess: You are swallowing or ignoring the exception at a higher level.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Digital man: "You are, in short, an idiot with the IQ of an ant and the intellectual capacity of a hose pipe."
|
|
|
|