|
Sean Michael Murphy wrote: It's not throwing an exception until you hit 4C, but you're not getting what you think you're getting. The Parse() method expects the string to be base 10 (decimal), not hex. Convert your hex value to decimal, then pass it in.
Even better, let the framework take care of the conversion for you. Check out this Byte.Parse() overload[^], passing NumberStyles.HexNumber in as the second argument.
|
|
|
|
|
Hi Everyone,
I have an application that I wrote in C# that allows users to back up their files to a network storage automatically. It uses the file modification times to figure out which files are newer on the computer than the storage location, and only copies the files it needs to on to the server.
The application starts a thread and the thread does all of the work in the background. What I would like to do is deploy the software to our computers and have it run automatically (and minimize itself) at system logon using a logon script.
I want my application to be able to detect when the CPU usage is at a certain level. If the CPU usage is below, lets say 20%, the application will do it's monitoring and copying. If the application detects the CPU usage rises above a certain threshold, it will suspend its operations and wait around for a while doing nothing.
I don't want the application running all of the time taking up CPU. My users run Photoshop and VS .NET and other applications simultaneously that take up most all of thier CPU.
Does anyone know of a way to detect what the current CPU usage is at? (Not the CPU usage of my application, but total CPU usage of all applications). I saw an article on here that gave you the usage of the current application, but it said it was difficult to do in .NET and they did not know how to do it.
Any help would be appreciated!
|
|
|
|
|
I have done this in ASP.NET, but I am having trouble with it in a C# windows app (that could be because this is my first c# project). At the moment I am just practicing skills against the northwind db.
I have a form with a datagridview bound to a SQL datasource. No problem. I can see and edit the northwind data just fine. I have a textbox that repeats the value of the first column of the selected datagridview row using SelectedCells[0].FormattedValue.ToString(). Works great.
Now, I have a list box that I would like to populate with data from a second table based on the value of SelectedCells[0].FormattedValue.ToString().
How do I do that?
Dave
|
|
|
|
|
Hi,
whats the preferred method of connecting to a database.
a)
create a static SqlConnection object
or
b)
using Sqlconnection = new... {}
having a Using section in every Add, Get, Delete function.
My question is, is having a static object connection open for the duration of the application, a major overhead?
Or is it better (all be it, more code) to have a Using statement, that connects, executes, then disconnects from the database? Thus no permanent connection.
Any thoughts?
Mark
|
|
|
|
|
Microsoft recommends the latter. The SqlClient provider maintains a pool of connection objects (adjustable via the connection string) for each process (the pool is actually keyed by the texet in the connection string, so you should take care to always use exactly the same string content). The ool largely eliminatesw the overhead of creating connection objects (the new... actually justs pulls an exixting idle connection from the pool) so what is left is onloy the overhead of opening the connection which is fairly small. The recommendation is to open the connection as late as possible, and close it as soon as you are done with the operation at hand. Keeping the connection open for the duration runs the risk that your process could terminate unexpectedly and leave a dead connection behind. This will not be reclaimed until the server is restarted. It also ties up a limited resource unnecessarily.
|
|
|
|
|
Microsoft recommends the latter. The SqlClient provider maintains a pool of connection objects (adjustable via the connection string) for each process (the pool is actually keyed by the texet in the connection string, so you should take care to always use exactly the same string content). The ool largely eliminatesw the overhead of creating connection objects (the new... actually justs pulls an exixting idle connection from the pool) so what is left is onloy the overhead of opening the connection which is fairly small. The recommendation is to open the connection as late as possible, and close it as soon as you are done with the operation at hand. Keeping the connection open for the duration runs the risk that your process could terminate unexpectedly and leave a dead connection behind. This will not be reclaimed until the server is restarted. It also ties up a limited resource unnecessarily.
Another reason not to do this is that should your connection become damaged (by a network or server fault) you have no way to recover other than to restart your entire process. Closing the connection when you are done with it (or on an error) and opening a new one whenever needed limits the damage to a single query, which could be retried.
|
|
|
|
|
Hi guys, I have this code:
public void showProcesses()<br />
{<br />
Process[] processes = Process.GetProcesses();<br />
List<Process> killList = new List<Process>();<br />
foreach (Process p in processes)<br />
{<br />
if (!(p.ProcessName == "System" || p.ProcessName == "Idle"))<br />
{<br />
string theProcess = p.MainModule.ModuleName;<br />
processesTest = processesTest + theProcess;<br />
killList.Add(p);<br />
}<br />
}<br />
richTextBox1.Text = processesTest;<br />
}
I keep getting the error: Error 1 'System.Windows.Forms.ColumnHeader' does not contain a definition for 'GetProcesses'
I have referenced System.Diagnostics too, this is really confusing! Any ideas anyone?
|
|
|
|
|
You perhaps named a Column as Process ?
|
|
|
|
|
Hi,
i got a big problem, i have to read in C# a propertyBag that was serialized in VB6 and persisted on a SQLServer Blob (IMAGE) field. So i got it from DataBase and tried Deserialize using this code
byte [] objSerialized = izDAL.loadSession(token)
MemoryStream memoStream = new MemoryStream(objSerialized);
BinaryFormatter binaryFormatter = new BinaryFormatter();
Hashtable sessionBag = (Hashtable)binaryFormatter.Deserialize(memoStream);
IDictionaryEnumerator en = sessionBag.GetEnumerator();
but i got this erros
{"BinaryFormatter Version incompatibility. Expected Version 1.0. Received Version 1426065408.740500660." }
Any idea? I'm using ASP.NET 1.4 framework...
Thx
|
|
|
|
|
The only time I've ever seen that error is in a remoting scenario where the remoting channel is a BinaryFormatter over HTTP. In that case, a problem at the server causes an error while the binary channel is initializing. (Usually it is an exception during channel binding)
The result is a binary error is passed to the client but the client recieves it as what is supposed to be an HTTP text stream. The binaryformatter checks what is returned expecting a version number sent to it (not a binary exception) and returns that failure message. Our workaround to this was to add a switch to the startup process telling the client to put the connection into a soap connection instead of a binary connection and that lets the real error message show.
|
|
|
|
|
I have been having a problem with the mouse button click event. When I double click the left mouse button, nothing happens. The code does not get executed. I need to click the right mouse button in order to get the desired code to execute for the control. That is, the code will not even begin the step through process until the right mouse button is clicked. This is peculiar indeed.
I would like to detect whether the left mouse button is clicked, and when the left mouse button is double clicked, I would like the control to behave as if it were the left mouse button that was double clicked. Also, I presume that there is a need to relate a double click to a single click with regard to the left and right mouse buttons.
I realize that there is an code like so:
private void _ctrl_DoubleClick(object sender, EventArgs e)
{
if (e.MouseButton == MouseButton.Left)
{
}
}
but that does not work. I would request some additional input. How could I get the mouse to only respond to the left mouse button double click without needing the right mouse button in order to perform the required code?
|
|
|
|
|
Hi all:
I am trying to write data back to the Access Database. The following method seems to work well. But I don't understand what the following piece of code exactly work.
<br />
public static void WriteToDatabase(string tableName)<br />
{<br />
System.Data.OleDb.OleDbDataAdapter<br />
databaseAdapter = new OleDbDataAdapter("Select * from "+tableName, conn);<br />
new OleDbCommandBuilder(databaseAdapter);<br />
try<br />
{<br />
databaseAdapter.Update(ds, tableName);<br />
ds.Tables[tableName].AcceptChanges();<br />
MessageBox.Show("Congratulations");<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
}
Could anybody explain it to me please? Or maybe you can give me a better way to write data back to access database please?
Thank you very much
Asura
|
|
|
|
|
hi
i think what are you missing is what the OleDbCommandBuilder dose !!
its define the sql commands from a specific adapter
Tamimi - Code
|
|
|
|
|
I need detect it, or at least know when the computer is connected, i think i can use wininet, but how? adding a timer and check if it's connected every second?
|
|
|
|
|
Congratulations on submitting almost one of the worst questions I've ever seen on the forum.
Try explaining in great detail: a) what are you doing b) what is going wrong c) what you suspect the problem is. And do it in clear English.
|
|
|
|
|
hi
i need to license component to create licence for my app (to Protect my app). does anybody take me free license component or source?
thanks .
|
|
|
|
|
I have a suspicion that one of the controls in my control array has not been properly instantiated. Because at least one of the controls in the control array was not instantiated properly when the form was loaded, then when those improperly instantiated controls in the control array are attempted to be randomized, they cannot be done properly because they were not instantiated properly in the first place. When I run the program without randomizing the control array, the application works fine.
Stephan was kind enough to provide some input as to how to randomize a control array. I should note that the randomization function itself works fine. The problem is somewhere possibly with the index in the control array. It is only when each of the elements from the randomized control array are parented to each other that I get the following error:
However, when I enable the randomization function, I get the following error:
"An unhandled exception of type 'System.NullReferenceException' occurred."
"Additional information: Object reference not set to an instance of an object."
I would really appreciate some insights as to how I could prove that each of the controls in the control array both before and after randomization has been properly instantiated. Trouble is, when I step through each of the steps, it appears to be a different control each time that it is not finding a reference assignment for the instance. I understand that there is a way to Trace() variables into a log file. Could somebody please provide a primer as how this is accomplished?
The slightly modified code for the randomization process is as follows. I would appreciate some additional input.
<br />
public CardControl[] cardName = new CardControl[53];<br />
...<br />
private void ShuffleCards(card[] cards)<br />
{<br />
ArrayList list = new ArrayList(this.cardName);<br />
Random rand = new System.Random();<br />
int j = 0;<br />
for (int k = 0; k < this.cardName.Length; k++)<br />
{<br />
j = rand.Next(list.Count);<br />
this.cardName[k] = (CardControl)list[j];<br />
string strCardName = this.cardName[k].Name;<br />
list.RemoveAt(j);<br />
}<br />
}<br />
Is there some kind of "Object Window" that I could use to see what objects have been instantiated correctly while stepping through the code. I would also need to know the properties of each object and their names.
-- modified at 14:53 Saturday 21st October, 2006
|
|
|
|
|
Do you put controls in all the elements in the array? Do you really have 54 cards in your deck?
---
b { font-weight: normal; }
|
|
|
|
|
Oops!!! You are right. I made the correction and now it works fine. For some reason, I always thought that 53 meant 52 but I always forget that it was really supposed to be the other way around. Thanks, Guffa!!!
-- modified at 15:35 Saturday 21st October, 2006
|
|
|
|
|
I've seen this sometimes in VB programs, where you specify the upper bound instead of the number of items.
Some programmers do this frequently without ever realising it, as dimensioning an item too much only causes an error if you use the size of the array and not a contant value, and only if you use the UBound function correctly, and don't think that it returns the number of items in the array.
---
b { font-weight: normal; }
|
|
|
|
|
Greetings:
I am a relatively new C# programmer and I have written a naive little utility which performs a task within a loop. This program is simple and the loop executes inside a routine belonging to the main form. The task that the loop performs does take some time though, maybe a few minutes, depending on various settings.
What I wanted, and this is the naive part, was to put some controls on the main form that update the user as to the status of the process. These are mostly just text boxes. When I want to update one or all of the text controls, I write the new string to the control's "Text" property.
What I have found though is that the form sometimes updates, but can go into this strange state of limbo where it simply stops updating or sometimes even goes blank. The main loop is still executing and the form will come back to life once the loop is finished. But I wanted the form to update continually throughout the process. I have also found that the form will update itself at first but if I click the mouse pointer on it or attempt to move the form on the display, then it freezes instantly and does not come back until the loop is finished.
I am an experienced MFC programmer and I know that this kind of thing happens if you fail to service the "message pump" from within loops of this sort. Have I missed something similar here? Or is this little utility simply an architectural accident-waiting-to-happen?
If the later is true, then what must I do to implement a long looping process that provides continually refreshed status to the user interface? Can you point me to books or articles?
Thanks in advance to anyone that responds
Mark
|
|
|
|
|
Do the loop in a new Thread and from there call yourcontrol.BeginInvoke() to update its contents.
This and this might help you
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Thank you. That worked.
M.
|
|
|
|
|
Hi all:
I am doing a windows form application. I need to some textboxes which can only be inserted numbers like prices. Is there any existing component in windows application of C# please? What's the best way of achieving this please?
Thanks alot
Asura
|
|
|
|
|
Process the KeyDown event and check, if it's a number:
try
{
int number = int.Parse(textbox.Text);
}
catch (Exception e)
{
}
You could also use a MaskedEditBox (or how that is called, I haven't used this one yet)
regards
modified 12-Sep-18 21:01pm.
|
|
|
|