|
Blackocebo wrote: Hello man,
I was impressed by your posts and i really need your help. i am creating a card game ( some kind of poker) to give it to my friend in order to play it for free and no more spend money to play it.
I have recently finished the game but i am facing a problem, when pressing the (DEAL) button sometimes, at some points, the application freezes. The CPU usage reaches 100%. So i want to ask you as an expert what should i do.
[lengthy code not included]
Well, let's look at a part of the code:
num2 = randomnum.Next(1, 14);
kind2 = randomnum.Next(1, 5);
string string2 = num2.ToString() + kind2.ToString();
while (string2 == string1)
{
num2 = randomnum.Next(1, 14);
kind2 = randomnum.Next(1, 5);
}
As you don't change any of the strings inside the loop, that you use in the condition, if you ever enter into the loop, you will never exit.
The same of course applies to the three following loops too.
---
b { font-weight: normal; }
|
|
|
|
|
I want to thank u very very much ...
Respect
|
|
|
|
|
i want to write a applicatin that delete files from a specific directory how can i do this?
can any one show me a sample code to achieve this or point me to the class that can be used to do this
kenny
|
|
|
|
|
Look at the System.IO namespace, particularly the Directory and Files classes. The Directory class as a static GetFiles member that gets a list of files and the File class has a static Delete method that can delete the file.
foreach(string file in Directory.GetFiles([path])<br />
{<br />
File.Delete(file);<br />
}
|
|
|
|
|
How can i manage database transactions between layers? Using Presentation, business and data layers. One solution i found is to declare transaction in the business layer then pass it as parameter to the DAL, but i think that's the worse i can do. Any ideas?
Never argue with an idiot. They drag you down to their level, then beat you with experience. - Dilbert
|
|
|
|
|
That depends on what you're using. If you're .Net 2.0 and all on the same machine, just use the System.Transactions namespace. Open up a TransactionScope and every call that gets made within that will subscribe to that transaction automatically. If you're in .Net 1.1, you could use COM+ (System.EnterpriseServices) and carry the transaction that way. If you're on different machines separated by web services or remoting, it gets a little more complex. In .Net 1.1 and 2.0 you can use TIP (Transaction Internet Protocol), which is a part of COM+ to handle transactions across machines. But an even better solution comes with .Net 3.0 where WCF gives you the ability to carry transactions across services very easily.
I have an article on TIP[^] and an article on WCF[^] that explains how to spread those transactions across machines. Essentially you can start a transaction in the presentation layer and even if the DAL is on another machine, it can subscribe to it.
|
|
|
|
|
ok. Everything is on one machine... i'm going to try with TransactionScope then, and look for some article. Thanks for answer this Dustin, i needed the advice because i'm just starting using layers.
Never argue with an idiot. They drag you down to their level, then beat you with experience. - Dilbert
|
|
|
|
|
Hello,
I have a .MHT file with my C# application, I use WebBrowser control to navigate to it at runtime. Is it true that the user should have outlook installed in order to display the mht file correctly as it's stated on MS site:
NOTE: "Web archive" is available only if Outlook Express is installed. The ability to save a Web page as a Web archive file is provided by the Inetcomm.dll file (the Microsoft Internet Messaging API file), which is installed by Microsoft Outlook Express 5.
http://support.microsoft.com/kb/221787
Please advice. Thanks.
|
|
|
|
|
I take it as gospel, after I tried it without Outlook Express installed. BTW, I think OE is installed by default in every Windows installation since Windows 98. You'd probably have to build a machine from scratch to test this. A Virtual Machine, like VMWare or Microsoft's Virtual PC, is great for stuff like this.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
You might check for the existence of the file Inetcomm.dll
I found mine in C:\WINDOWS\system32\
string path = "%SystemRoot%\system32\Intercomm.dll";
path = System.Environment.ExpandEnvironmentVariables(path);
bool isExist = System.IO.File.Exist(path);
A better way might be to try to load the outlook object as a com object though. Then, if someone decides that library should get merged into another library, or decides to change the filename, or decides that dolphins should rule the earth, then you will still be golden if someone was smart enough to leave the functionality somewhere that the com object can get to it.
|
|
|
|
|
I have a custom control that I has embedded controls.
When I show a messagebox, the messagebox shows up behind the form.
Topmost on the form is set to false.
OpenFileDialog works as it is supposed to, why not messagebox?
Any ideas?
private void button13_Click_1(object sender, EventArgs e)
{
item i = new item();
Button b = new Button();
b.Text = "hello";
b.Click += new EventHandler(b_Click);
subItem s = new subItem("hello");
s.EmbeddedControl = b;
i.SubItems.Add(s);
this.myListView1.Items.Add(i);
}
void b_Click(object sender, EventArgs e)
{
//using (OpenFileDialog dlg = new OpenFileDialog())
//{
// dlg.ShowDialog(this);
//}
MessageBox.Show(this, "hello");
}
|
|
|
|
|
Instead Use MessageBox.ShowDialog(),
if u deliberately want to use MessageBox.Show mean pass the mainform's handle as the first parameter(owner) of Messagebox.Show
|
|
|
|
|
Hey all,
I'm encapsulating the SetWindowsHookEx() function in order to capture all keyboard messages.
I'm raising KeyEventHandler events from my class, so I'm planning to use the KeyEventArgs object, of course.
When capturing keyboard messages I get the key-code for the pressed key.
To instantiate a KeyEventArgs object, I need a System.Windows.Forms.Keys value.
Anybody got an idea as for how to get the appropriate Keys value
without using a large switch statement involving a case for every key on the keyboard??
Thanks in advance,
Shy.
|
|
|
|
|
I think you can just cast them, the Keys enumeration has the appropriate values defined for each character code.
Sig cops got me...
|
|
|
|
|
What about the numpad keys, space bar, etc...?
BTW... Is there any way to print the value of an enum?
Something like:
Keys k;
k = Keys.A;
Console.WriteLine(k.ToString()); The above code prints "A" BTW...
|
|
|
|
|
You could do:
Console.WriteLine("{0}.{1}", k.GetType().Name, k.ToString()); That's the simplest way I think.
Sig cops got me...
|
|
|
|
|
You could do:
Console.WriteLine("{0}.{1}", k.GetType().Name, k.ToString()); That's the simplest way I think.
Sorry forgot to answer your first question. The NumPad keys etc are still characters, just assigned a value outside the normal "visible" range. E.g. Esc is char(13) I think.
Sig cops got me...
|
|
|
|
|
Thanks, but that's not what I was looking for...
I want to be able to print the key code...
k.ToString() returns the name of the key...
|
|
|
|
|
Ah, I see what you want, cast it to an int then and you get the value
Console.WriteLine((int)k);
Sig cops got me...
|
|
|
|
|
Thanks a bunch!
|
|
|
|
|
I have a problem when trying to close a connection or the odbcdatareader if I stop it from doing Read() before it would normally be done it hangs. I saw something similar when I Googled this a while ago, but can't find it now. Apparently, the while(dr.Read()) doesn't actually stop even though I used a break; to get out of the while() loop. Anybody run into this before?
|
|
|
|
|
show is a small code snippet of the loop. I have a feeling you're missing something that is causing the loop to continue, and not actually hitting the line to break out of the loop.
|
|
|
|
|
No, I don't think that's it because it breaks from the loop with no problem. I put a breakpoint on the line immediately following the loop and it goes directly there with no problem. This function is being done in a thread of its own so that the user can press 'Cancel' and also updates the UI correctly.
Here's a snippet of what I'm doing:
while (statreader.Read() && !m_bCancel)
{
stemp = statreader["aj_vchar"].ToString();
this.progressBar1.Increment(1);
}
this.progressBar1.Value = 0;
statreader.Close();
I've tried calling Close() on the connection first. I've tried calling Dispose() instead, and I've tried not closing it at all to see what happens when it goes out of scope (statreader). No matter what, this reader hangs on close depening on how many records are in the reader.
When I try it on a test database that returns only a few thousand records, Close() only takes a few seconds. When I try it on a database with about 400,000 records being returned, it takes about 10 minutes for Close() to finish executing.
|
|
|
|
|
Can you show me where you're opening the connection? I'm guessing this would shed more light. Are you creating the DataReader object with the option "commandbehavior.closeconnection"?
|
|
|
|
|
The following comes directly before what I posted earlier:
using (OdbcConnection conn = new OdbcConnection(source))
{
conn.Open();
statcmd = new OdbcCommand("select * from tblPeople", conn);
statcmd = new OdbcCommand(sql, conn);
OdbcDataReader statreader = statcmd.ExecuteReader();
No, I'm not using "commandbehavior.closeconnection" option. Never knew it existed.
|
|
|
|