|
vasavi.p wrote: when this Quescnt and the MaxValue in RandomClass.Next(Min, Max) are equal, its going to infinite loop
No, it's going to infinite loop under all circumstances.
Try running it though the debugger. What is your "code" actually doing?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
There's a debugger ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Yeah - you just have to enable it:
Type "Format c: /s" at a command prompt and press ENTER. Just say YES to any of those silly questions, you don't need to read them...
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I'll stop pressing ENTER before using this debugger.
|
|
|
|
|
hi
try with the below code
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "";
int Quescnt = 6;
string Randomnos = string.Empty;
for (int i = 0; i < Quescnt; i++)
{
int RandomNumber = RandomClass.Next(28, 37);
if (!Randomnos.ToString().Contains(RandomNumber.ToString() + ","))
{
Randomnos = Randomnos + RandomNumber.ToString() + ", ";
}
else
{
Quescnt++;
}
}
Label1.Text = Randomnos;
}
and try with this too[this will go to infinite loop]
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "";
int Quescnt = 6;
string Randomnos = string.Empty;
for (int i = 0; i < Quescnt; i++)
{
int RandomNumber = RandomClass.Next(28, 33);
if (!Randomnos.ToString().Contains(RandomNumber.ToString() + ","))
{
Randomnos = Randomnos + RandomNumber.ToString() + ", ";
}
else
{
Quescnt++;
}
}
Label1.Text = Randomnos;
}
|
|
|
|
|
I am not even going to look at them until you have preserved the formatting - why should I even slightly struggle? Remember the "code block" button above?
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I will refrain form making any comment except to point out that you have the following for loop:
for (int i = 0; i < Quescnt; i++)
and within this loop you have the following statement
Quescnt++;
Using the debugger could have helped you locate this fairly quickly.
|
|
|
|
|
Irrespective of this error, s/he's not going to get 6 unique random numbers from a range of only 5 possibilities.
|
|
|
|
|
J4amieC wrote: Irrespective of this error, s/he's not going to get 6 unique random numbers from a range of only 5 possibilities.
I thought s/he's complaining that it goes into an infinite loop. There seems little point in worrying about anything else until that logic is fixed.
|
|
|
|
|
I thought it was going into an infinite loop because its looking for the next unique random number, and all possibilities have already been found.
|
|
|
|
|
J4amieC wrote: I thought it was going into an infinite loop because its looking for the next unique random number, and all possibilities have already been found.
In the following code:
for (int i = 0; i < Quescnt; i++)
{
int RandomNumber = RandomClass.Next(28, 33);
if (!Randomnos.ToString().Contains(RandomNumber.ToString() + ","))
{
Randomnos = Randomnos + RandomNumber.ToString() + ", ";
}
else
{
Quescnt++;
}
}
every time it hits the else clause it is incrementing Quescnt so the for loop will keep going because Quescnt will always stay ahead of the loop variable.
|
|
|
|
|
vasavi.p wrote: and try with this too[this will go to infinite loop]
Now for extra credit (that is, beyond being able to blindly paste your code into this window) can you tell us why this goes into an infinite loop?
Hint:-
Documentation :Random.Next(Int32,Int32)[^]
Relevant part of documentation:
minValue
Type: System..::.Int32
The inclusive lower bound of the random number returned.
maxValue
Type: System..::.Int32
The exclusive upper bound of the random number returned. maxValue must be greater than or equal to minValue.
|
|
|
|
|
|
Hi all
on form closing event i check if it is windows shutdown and if yes i uninstall the program it is not working for me.
i tried writting to a log file on form closing event if it is windows shutdown it worked.
from another application on ckick of a button also the uninstall program worked.
plz help me
private void ChatApplication_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.WindowsShutDown)
{
Uninstall();
}
}
private static void Uninstall()
{
Process oProcess = new Process();
oProcess.StartInfo.FileName = "cmd.exe";
oProcess.StartInfo.CreateNoWindow = true;
oProcess.StartInfo.UseShellExecute = false;
RegistryKey oRegKey = null;
string sUninstallString = "";
string[] asSubKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\").GetSubKeyNames();
foreach (string sSubKey in asSubKeys)
{
oRegKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" + sSubKey);
if (oRegKey.GetValue("Displayname") != null && oRegKey.GetValue("Displayname").ToString() == "Setup1")
{
sUninstallString = oRegKey.GetValue("Uninstallstring").ToString();
break;
}
}
if (sUninstallString.LastIndexOf("exe") != (sUninstallString.Length - 3))
{
sUninstallString = sUninstallString.Remove(0, 14);
oProcess.StartInfo.Arguments = "/k msiexec.exe /x" + sUninstallString;
}
else
{
sUninstallString = sUninstallString.Replace("C:\\", "");
string sExe = sUninstallString.Substring(sUninstallString.LastIndexOf('\\') + 1);
sUninstallString = sUninstallString.Remove(sUninstallString.LastIndexOf('\\'));
oProcess.StartInfo.Arguments = ("/k cd\\ & cd " + sUninstallString + " & " + sExe);
}
oProcess.StartInfo.RedirectStandardError = true;
oProcess.Start();
oProcess.WaitForExit();
oProcess.Close();
oProcess.Dispose();
}
|
|
|
|
|
You need to stop the form from closing ( by setting the event args ), then close it AFTER you have run your program. Even then, if windows is shutting down processes in general, I'm not sure it will work. You could perhaps put the uninstaller in the runonce registry key, so it uninstalls on startup.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i tried to stop the form closing event also i that case it is giving me some error. which states the formate of the file is not correct i dont find any link between this error and my application. plz help me
|
|
|
|
|
|
sorry to say u this method has no effect on the shutdown procedure of windows
|
|
|
|
|
Thought you were talking about app window
|
|
|
|
|
I'm curious, what is the reason for uninstalling your app when closing down. Seems a little drastic to me.
|
|
|
|
|
im not uninstalling the same application that im running im uninstalling any setup1 if previosly installed by me by mistake.
|
|
|
|
|
remoting dll >>>>
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
namespace Remoting
{
public class ChatServer : MarshalByRefObject
{
ArrayList client = new ArrayList();
public void AddClient(string s)
{
client.Add(s);
}
public ArrayList AllClient()
{
return client;
}
}
}
Server code >>>>>>>>
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using Remoting;
namespace Server
{
public partial class Form1 : Form
{
ChatServer server;
public Form1()
{
InitializeComponent();
HttpChannel ch = new HttpChannel(8080);
ChannelServices.RegisterChannel(ch, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(ChatServer), "CS", WellKnownObjectMode.Singleton);
}
private void ShowClients_Click(object sender, EventArgs e)
{
server = new ChatServer();
ArrayList cn =server.AllClient();
foreach (string c in cn)
{
listBox1.Items.Add(c);
}
}
}
}
client code >>>>>
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;
using Remoting;
namespace Client
{
public partial class Form1 : Form
{
ChatServer client;
public Form1()
{
InitializeComponent();
HttpChannel ch = new HttpChannel();
ChannelServices.RegisterChannel(ch, false);
RemotingConfiguration.RegisterWellKnownClientType(typeof(ChatServer), "http://localhost:8080/CS");
client = new ChatServer();
client.AddClient("AAA");
}
}
}
>>>>>>>>> when i click on showclient its not showing ........ what is the problem.
Thanks in Advance
|
|
|
|
|
Have you stepped through the code ? Why on earth are you using the ArrayList class ? It's obsolete.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
i am using arraylist to store all the clients name. i know its obsolete. well i can change it not a problem....
but what is the main problem why i am not getting the connected client when i am clicking on button showclient_click
help me
|
|
|
|
|
Well, I don't know. I am just wondering if you can explain what you've done to help yourself, using the debugger,etc. If you can tell us what line of code isn't doing what you expect, it would help us to narrow it down, without having actually build your code and run a client/server to see what happens.
Someone who has done more of this sort of work than me may come along and just answer it, but in the meantime, I think it's valuable to explore the things you should have mentioned in your original post, like what happens when you run it in the debugger.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|