|
I'm trying to build a stock market game this game uses the thread too much but the problem is whenever i close the game the game stays in the memory and i can't run again unless i close it manually from the task manager .
Thank you.
Asaad
|
|
|
|
|
I guess you musty mean you are using multiple threads - if so, you need a way to stop those threads when terminating the main program you should either abort those threads, or signal them to stop, and wait for them to reach a thread.join.
A clearer explanation of your problem might help, along with a small sample of the offending code...(read "how to get an answer to your question" at the top).
|
|
|
|
|
Thank you for your reply.
This is the code where i abort the threads
private void Game_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
this.tickerThread.Abort();
this.timerThread.Abort();
this.checkPrice.Abort();
}
catch{}
}
but when i close the program it still work in the background . and i must terminate it manully .
should i add some code or what ?
|
|
|
|
|
Are you catching exceptions in your worker threads? If so, how do you handle ThreadAbortException?
A typical pattern might be:
public volatile bool quit;
public void runtickerThread()
{
try
{
while(!quit)
{
DoStuff();
}
}
catch(ThreadAbortException)
{
Thread.ResetAbort;
quit = true;
}
catch(ApplicationException)
{
}
finally
{
}
}
private void Game_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
this.quit = true;
this.tickerThread.Abort();
this.tickerTread.Join();
}
catch{}
}
|
|
|
|
|
To the "Code Project" community, I thank you for reading my question.
I am creating a business application (C# windows app) for my parents, and one of my worries is that I need to create some type of method of incrementing the "Order Number" or "Invoice Number" every time a new order is created, regardless if the program is running 24/7 or if the application is closed. ... Basically, I need a method to allow the application to remember what "Order/Invoice Number" it was on and increment it by one every time the application prints a form and saves the number for the next invoice somewhere (either within the program or a clever memory usage, I am not too clever today...).
Right now I am using a disabled and unviewable NumericUpDown control to control the order/invoice number and a label to display it. I think this can work, but I do not know how to have the program automatically save the number and increment it for the next form when it opens up again. I can increment it once, but how to do it every time when a new order is needed?
I hope I am clear... But please be kind in letting me know if I am not clear or if some type of Dynamic Binding or some advanced feature I don't know about will help me out with this.
Thanks for the help!
- Charles
|
|
|
|
|
How are you storing the orders and invoices? If you are storing them in the database you can easily get the highest number used so far.
Example SQL query:
"select max(OrderNumber) as HighestOrderNumber from Orders"
---
b { font-weight: normal; }
|
|
|
|
|
I'm not worried about the orders themselves for now (I might just use the Print prompt), but I do not know how exactly to store the number... As I read someone else said, I might as well use a database and save the number there... but thanks for the help! I'm going to give this a try. Thanks!
|
|
|
|
|
By the way... I was wondering if the statement works as it does (except with the given variable names...), and where would I type the code - before I finish developing the oleDbDataProvider (where I develop the table using SQL statements)? I'm storing the invoice number in a MS Access database (that's all I think I need to store at this point)... Is that fine?
I thank you for your continued support.
- Charles
|
|
|
|
|
Is your application connected to a database?
The reason I ask is that using a database will be a lot easier, I would think, than rolling your own, which is the impression I get from what you've written. A database should provide you with an "auto number" which auto increments itself for each new record.
Admittedly, this is an area outside of my expertise, so there's not a lot more I can say. But I would suggest investigating using a database. Heck, if your parents have Access on their computer, you could design a small database for them complete with forms for them to enter order information.
If you want to continue with the C# app and need to keep track of a number, then just save the last invoice number to a file right before the application is closed. When the application is run again, it reads the file and initializes the up/down control.
Anyway, hope some of this helps.
|
|
|
|
|
Is there a more efficient timer than the standard one? I am using on on a 1 second tick, and it's lagging my app badly
|
|
|
|
|
Depends how you are using it, but it shouldn't cause a noticable lag.
only two letters away from being an asset
|
|
|
|
|
Im using a System.Timers.Timer, which runs when the app loads.
The lag happens on each tick, might it be the code within the tick thats causing the lag rather than the timer? (Its calling a tiny xml feed from a server).
Would the loading of the xml page cause the lag do you think?
|
|
|
|
|
It's definitly not the Timer that's causing the lag. It's got to your Tick code. The lag is probably comming from the time it takes to get the file from the server.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Ah, damn. You reckon if I tried multi threading the xml retrieval it might stop the lag at all?
|
|
|
|
|
You'd have to move the code to another thread to avoid the lag. Check into using the System.Threading.Timer instead. Your code will be called on a background thread using this Timer.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
What Timer are you using now? The FrameworkTimer in the DirectX SDK is the fastest in .net...
/\ |_ E X E GG
|
|
|
|
|
Hi folks,
Does anyone know of a way I can convert a string into a resource?
Ie, like this?
String sound_file = (myResource);
<do convert here>
spWave.Stream = sound_file;
Basically I need the string to be a properties.resource value...
Thanks, Ben.
-- modified at 16:30 Friday 4th August, 2006
|
|
|
|
|
You want to add a string into the resources during runtime? That isn't possible because the resources are contained within the static executable.
Why do you need to add a string to your resources?
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I dont want to add the string as a resource, but reference the resource from a string.
So if I want to play the resource: Properties.Resources.mysound;, I want the string sent to the function to represent mysound.
|
|
|
|
|
I still don't understand. If you want to play the resource Properties.Resources.mysound, you'll need to convert it to a stream or file and use System.Media.SoundPlayer to play the sound.
You said "I want the string sent to the function to represent mysound". Can you clarify that? What string? What function?
|
|
|
|
|
I have an unmanaged C++ DLL which has the following structures,
typedef struct {char str[200]; } MYARRAY1;
typedef struct {MYARRAY1 myarray1struct;} MYARRAY2;
typedef struct {MYARRAY2 myarray1struct[5];} MYARRAY3;
To return MYARRAY2, I used the following entry function,
extern "C" __declspec(dllexport) void CallTestArray2( MYARRAY2 *pStruct)
To return MYARRAY3, I used the following entry function,
extern "C" __declspec(dllexport) void CallTestArray3( MYARRAY3 *pStruct)
In C#, I declared the following structures,
[StructLayout(LayoutKind.Sequential)]
public struct MyArray1
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=200)] public String str;
}
[StructLayout(LayoutKind.Sequential)]
public struct MyArray2
{
public MyArray1 tempArray1;
}
[StructLayout(LayoutKind.Sequential)]
public struct MyArray3
{
public MyArray2[] tempArray2;
}
I do not have any problem using DLLImport call to C++ DLL to get data in MyArray2, however when I try to get data in MyArray3 with the following code, all data in testArray3 are empty.
MyArray3 testArray3 = new MyArray3();
testArray3.tempArray2 = new MyArray2[ 5 ];
CallTestArray3(ref testArray3);
Any help is appreciated!!!
|
|
|
|
|
vitowong wrote: [StructLayout(LayoutKind.Sequential)]
public struct MyArray3
{
public MyArray2[] tempArray2;
}
Underlined should be also marshaled.
|
|
|
|
|
MyArray2 is based on MyArray1, and MyArray1 has been marshaled. Is it need for MyArray2[] be marshaled? I tried to marshal as AsAny, but it doesn't work. What do I be marshal as? Thanks.
|
|
|
|
|
I am building an application that must take one Dataset table apart and display it in two different DataGridView's along with one additional field from a second table.
I'm iterating through the transactions and building out a DataTable for each set of records. (this part works nicely) Then set my grids as follows:
payView.DataSource = new DataGridView( payData );
refView.DataSource = new DataGridView( refData );
So far so good, everything works...almost. I have one column defined as a DataGridViewCheckboxCell and that column is not bound to any data. The remaining columns ARE bound to my fields in my data tables and all of them are readonly. My DataGridViewCheckboxCell is marked as ReadOnly=false and I even tried marking my DataGridView as ReadOnly=false. All to no avail. If I click on it, the cell never changes value and remains unchecked. Here is my column definition:
this.selected1 = new DataGridViewCheckBoxColumn();
this.selected1.ReadOnly = false;
this.selected1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.selected1.HeaderText = "Sel";
this.selected1.Name = "paymentSelect";
this.selected1.Resizable = System.Windows.Forms.DataGridViewTriState.False;
Finally I wanted to highly a cell that fell outside the allowed parameters. The logic works well. The cell is identified and the cell.Style was set to a new highlightedStyle object with a light red background color. However the DataGridView never changes the background painting. The only way I got it to work is by hooking into the RowPrePaintEvent and setting the background color there. Why is it working like this??? Why is this control being so difficult to work with????
Any help in getting the checkbox to function properly would be greatly appreciated.
|
|
|
|
|
Unbound CheckBoxColumn works fine here, just click Colums property of the DataGridView in the designer, add the unbound column, and voila, perfectly editable. Here's the designer generated code:
private void InitializeComponent() {<br />
this.dataGridView1 = new System.Windows.Forms.DataGridView();<br />
this.Column1 = new System.Windows.Forms.DataGridViewCheckBoxColumn();<br />
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();<br />
this.SuspendLayout();<br />
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;<br />
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {<br />
this.Column1});<br />
this.dataGridView1.Location = new System.Drawing.Point(-4, -1);<br />
this.dataGridView1.Name = "dataGridView1";<br />
this.dataGridView1.Size = new System.Drawing.Size(297, 271);<br />
this.dataGridView1.TabIndex = 0;<br />
this.Column1.HeaderText = "Column1";<br />
this.Column1.Name = "Column1";<br />
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br />
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br />
this.ClientSize = new System.Drawing.Size(292, 268);<br />
this.Controls.Add(this.dataGridView1);<br />
this.Name = "Form1";<br />
this.Text = "Form1";<br />
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();<br />
this.ResumeLayout(false);<br />
}<br />
Wout
|
|
|
|