|
Follow Dennis' link to the Application.StartupPath(). The problem your having is that your assuming that the current directory will never change when you app is open. This is simply not the case. As you've found out, it can change at any time.
When you code file paths, NEVER use just a filename. ALWAYS prefix your filepaths with a complete path specification. You can use the Application.StartupPath() to return the directory path that your .EXE was launched from. Then use the Path class' Combine() method to build a full path specification to your .XML file.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I have a class that produce a number. I would like to store the class as a object in a array. The problem is that the class only produce a number the first time, and by some reason seems to keep the next time i call it.
Anyone who can help me?? Thanks // Niklaz
point[] m_point = new point[5];
private void button2_Click(object sender, System.EventArgs e)
{
int x;
for(x=0 ; x < 5; x++)
{
point p = new point();
m_point[x] = p ;
}
public class point
{
public int x ;
Random ran = new Random();
public point()
{
x= ran.Next(100);
}
}
|
|
|
|
|
You need to seed Random in order to get a random starting point in the pseudo random generation of numbers. DateTime.Now.Ticks is a good one.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Christian Graus wrote:
You need to seed Random in order to get a random starting point in the pseudo random generation of numbers. DateTime.Now.Ticks is a good one.
That won't do the trick. Random Constructor ()[^] already uses a time-dependent seed. The problem (even if I explicitly use (int)DateTime.Now.Ticks as the seed) is that a tick is defined as 100 nanoseconds which is quite a long time on a modern CPU. The only way to work around this problem with multiple instances of Random would be to throw in some of these: Thread.Sleep(20)
Best regards
Dennis
|
|
|
|
|
Good point. A more sensible move IMO would be to accept the value in the constructor, or make the Random object static inside the class and seed it in a static constructor.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Niklaz wrote:
I have a class that produce a number. I would like to store the class as a object in a array. The problem is that the class only produce a number the first time, and by some reason seems to keep the next time i call it.
Christian is right that the seed is the problem. However, assuming that you're not doing some intense multithreading the easiest solution would be to simply declare ran as static.
public class point
{
private static Random ran = new Random();
public int x;
public point()
{
x = ran.Next(100);
}
}
Best regards
Dennis
|
|
|
|
|
windows application vs console application mode (1/20/2005 12:51:40 PM)
hello I have a following problem,
i am trying to make a windows form app in c# (.net visual studio) which would be using ndis protocol driver,
for this i need to be able to open a driver file with a handle, which i could then use with function DeviceIoControl() to bind the ndis driver handle to the specific nic device
but i cant find functions in form app mode corresponding to CreateFile() returning a handle to a file and DeviceIoControl() (they both work fine in console app mode)
-------------------------------------------------------------------------
No You have something else going on here (1/20/2005 1:56:34 PM)
You can set references and using statements in a Windows Forms app or in a Console App exactly the same. The only difference is the console app has no Windows GUI, and can response to event-driven programming, whereas a console app is basically linear within its Main method.
Better go back and check your code.
-------------------------------------------------------------------------
appearently not, another question:ms-help binding (1/20/2005 2:30:15 PM)
thanks for reply
i also find it strange but it seems that windows form app simply can't use CreateFile() function while the console app can
when you create same basic apps both in console and form mode and put
IntPtr handle = CreateFile() in a constructor in both apps
the compiler in windows form app will throw an error: no such function in namespace
i also have another question about msdn docs
tried almost everything but i am unable to view help in VS or the msdn docs browser
i keep getting the white unable to open page, i suppose it has something to do with ms-help:// binding, maybe its a service which has a problem?
|
|
|
|
|
pilaf wrote:
i also find it strange but it seems that windows form app simply can't use CreateFile() function while the console app can
This simply is not true. CreateFile is used by just about every single Windows Forms application there is.
pilaf wrote:
when you create same basic apps both in console and form mode and put
IntPtr handle = CreateFile() in a constructor in both apps
the compiler in windows form app will throw an error: no such function in namespace
In either case of a Console app or Windows app, the method for calling Win32 API functions is exactly the same. There are no limitations on either application calling into the API. I'm sorry, but it's you who is making the mistake. Without seeing your code, though, it's impossible to tell you what your doing wrong.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
The project I am on reads from a DVD-ROM if one is installed on the client PC. So I need to disable a control if the machine doesn't have the drive. My question is how can my application check for the presence of a DVD-ROM?
I know I can get the logical drive letters from Directory.GetLogicalDrives() , but this doesn't give me any information about what type of drives are on the system.
|
|
|
|
|
I've got a small application that keeps track of a number of small tasks using a threadpool, which suits the soltuion fine.
I'm running 6 objects at a time, and they work fine. However, while attempting to reduce the load on the CPU from some of the processes spin/waiting, I added a ThreadSleep.
This has caused the display to behave oddly. The ThreadSleep seems to free the resources used by the particular thread of the ThreadPool. Which causes the next item in the queue to be processed with the same local values as the item i just put to sleep. (The list basicaly displays blocks of replicataed items)
This is causing me a degree of confusion, as well as a problem, as I do not want to release the thread, simply pause it for 1-2ms per itteration of the process.
Is there anyway to pause a ThreadPool thread, without releasing it?
I've tried using ThreadSpin, but this still chews up a large chunk of CPU power unesscesarily, so i'm looking for an alternative solution.
Cheers
Cata
|
|
|
|
|
Are there any bittorrents written in c# that have source code available. Are there any c++ ones?
|
|
|
|
|
Ask google.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
If i use ArrayList to get the data in database
(I copy this code from the internet)
ArrayList array = new ArrayList();
this.command.CommandText = "SELECT * FROM " + table + " ORDER BY " + ordering;
this.reader = this.command.ExecuteReader();
while (this.reader.Read())
{
ArrayList a = new ArrayList();
for (int i = 0; i < this.reader.FieldCount; i++)
a.Add(this.reader[i]);
array.Add(a);
}
this.reader.Close();
return array;
How to show all value in Arraylist. Please show me the code. I use for loop already but it always show System.Collections.ArrayList. Thank you.
|
|
|
|
|
You really should consider not using an ArrayList to temporarily hold the values just to display them later. If you're going to do that, use a DataAdapter instead to fill a DataSet , which is basically a list of tables which contain a list of rows which a lot more information than what you're storing. The beauty of a DataReader is, though, fast forward-only access to data. The best approach is to enumerate the data as you read it, not store it and read it later.
Also, DO NOT construct SQL expressions using string concatenation. I grow tired of saying this but will again because is one of the most common ways to get hacked. All I need to do is pass "Table1; DELETE FROM Table1; --" (where Table1 is some table I can select) and your data is gone. Got customer information? I could select it and you get sued for privacy violations.
Construct SQL expressions using the IDbCommand implementations, like SqlCommand for SQL Server and OleDbCommand for OLE DB connections including Access. There's others as well. This also encodes values for you. See the SqlParameter class and SqlCommand.Parameters property documentation in the .NET Framework SDK for more details.
To answer your question, though, you need to loops because you're adding an ArrayList to an ArrayList :
foreach (ArrayList list in array)
{
foreach (object obj in arr)
Console.Write("{0}, ", obj);
Console.WriteLine();
} Again, though, if you must store the data use a DataSet , which allows you to define tables, columns, store tracking information to later update the database is necessary, easily bind it to controls (even using the designer to easily bind them to controls like the DataGrid ) and more.
Be sure to read Accessing Data with ADO.NET[^] for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Could u show me how to use SqlParameter
|
|
|
|
|
Read the documentation[^] for the SqlParameter class, as well as the documentation[^] for the SqlCommand.Parameters property as I said in my first reply.
The documentation is there to help you learn. Forums like this exist to help explain what you don't understand or help in cases where the solution isn't so obvious unlike your problem.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have an array of doubles that I wish to pass to a method declared in a COM ActiveX control. The documentation for the ActiveX control says the method is declared as:
<br />
AddParametricCPP(BSTR Name, double Start, double Step, double* Y, long Size)<br />
where Y is the parameter I'm having issues with, and is documented as:
"Pointer to an array of doubles, holding the y-values of the curve."
When the VS.NET IDE imported this OCX it declared the method signature as:
<br />
AddParametricCpp ( System.String Name , System.Double Start , System.Double Step , System.Double Y , System.Int32 Size )<br />
where Y is a reference parameter.
What is the proper method of passing an array of doubles to this method through the Y parameter? I have tried all sorts of different things, but I keep getting a nullreferenceexception. I am sure the other parameters are correct so it must be in the way I am passing the array. Any suggestions on the proper way to accomplish this task?
|
|
|
|
|
There should be an out or ref for parameter Y . Please provide the exact signature if you haven't.
If there is no such keyword, then you'll have to declare that interface yourself, making sure to attribute the interface with the correct GuidAttribute value and the appropriate InterfaceTypeAttribute , as well as declaring the methods in the correct order for IUnknown and dual interfaces, or the correct DispIdAttribute values for IDispatch or dual interfaces. If you must define the method yourself, then declare it as double[] . Also add MarshalAs(UnmanagedType.LPArray) to the parameter declaration to marshal it as a pointer to a double , setting the MarshalAsAttribute.SizeParamIndex to 4 to indicate that the Size parameter contains the number of elements for the native array (since native code knows no bounds for native arrays).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi every one ..
i use C#.NET 2003 , I developed program which contains reports generated with crystal report 9.0 ..
when i run that program after .Net framework 1.1 setup on any other machine , reports generate an exception say
"Missing or invalid Keycodev2.dll", but i verified that file and find it on "Crystal Decision Folder"
.. If Any Can Find a solution to that problem please contact me on
shadyaly2003@gmail.com or
shadyaly2003@yahoo.com
thank you .....
|
|
|
|
|
Read Deploying Crystal Reports in .NET Applications[^]. It contains important information about required steps to package and distrubute Crystal Reports for .NET, like including the Crystal_regwiz2003.msm merge module and setting the LicenseKey property from the PropertyGrid. This key is the key you registered when first using Crystal Reports on your developer box. You can also get it from the About->Help dialog.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I'm just exploring socked programming. I've written a small app that will load the headers of newsgroup messages and am struggling to get decent performance. I've stripped everything down so that the code simlpy readlns each response from the server and I've used a profiler demo and it would seem to indicate that a lot of the time of the code is spend in OSSOCK::recv, understandably. What I cannot work out is why it is taking so long. The connection to the server is fast enough and running other apps (e.g. newsreaders) confirms that it should not be taking so long. What can be done to improve the writer.WriteLine, Flush, readline() cycle
As an indication, the app will connect to a newsserver, download the headers for the last 100 messages. This takes over 20 seconds of which is way over the top.
Any pointers greatly appreciated.
Cheers,
Ian
|
|
|
|
|
Hey
I am developing a Server - Client.
Im using Async connection
and using
AsyncCallback recieveData = new AsyncCallback(OnRecievedData);
server.BeginReceive(m_byBuffer,0,0,SocketFlags.None,recieveData, server);
the size of mbyBuffer is 256.
But i am not realy using it, instead i am using
ForumPack.Command cmd = (ForumPack.Command)formatter.Deserialize(NStream);
to deserialize the command obje and a diffren one to deserialize the ombject that is comming after the command obj.
This is working fine, but when i disconnect and the connect again i get the error on
server.BeginReceive(m_byBuffer,0,0,SocketFlags.None,recieveData, server);
Connection lost becourse keeping-alive activity have notice an error.
What could be the error ?
When i am reconnecting i am setting connection object to null, and then i set it to a new object. Maby i have to clean up the old connection object better ?
//SnowJim
|
|
|
|
|
How to edit a data in Listview. It's Like click in column on listview and it can type and change data inside.
|
|
|
|
|
Use ListViewItem.BeginEdit . This only works if ListView.LabelEdit is true . The default value is false , so you'll need to set it. Using the ListView control defined in the BCL (base class library) you cannot edit other columns. If you search for "List View" on this site for the .NET and C# categories you should find several articles that describe how you can accomplish that.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I'm laying out the ideas for my complete revamp of the Quake 3 AI system, and to get there i need to test out pathfinding algorithms... and to get there i need to improve my programming.
Since i'm pretty new to all this, can someone please point me in the right direction?
This is want i want to be able to do:
Draw a basic 2d "map" that i can chuck all the results from the pathfinding simulation on.
The map includes:
--> Starting and ending point
--> waypoints
--> numbers, colors etc
--> basic lines, pictures
I take it those are just diffrent objects? i'm not quite sure how the objects work either...
Thanks in advance...
Serrix
The Multidisoctinal Metalobilist...
... Those are random words... don't google em
|
|
|
|