<pre>I Have an application that shows output of cpu utilization its memory used and current date and time in console application output now i want to store this 3 things in my database how can i store it?</pre>
-
using System.Diagnostics;
namespace cpu_performance
{
internal class Class1
{static void Main(string\[\] args) { PerformanceCounter cpuCounter; PerformanceCounter ramCounter; cpuCounter = new PerformanceCounter { CategoryName = "Processor", CounterName = "% Processor Time", InstanceName = "\_Total" }; cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "\_Total"); ramCounter = new PerformanceCounter("Memory", "Available MBytes"); Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + "%"); Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB"); Console.WriteLine(); while (true) { System.Threading.Thread.Sleep(1000); DateTime localDate = DateTime.Now; Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + " %"); Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB"); Console.WriteLine("Local date and time: {0}, {1:G}", localDate.ToString(), localDate.Kind); Console.WriteLine(); if ((int)cpuCounter.NextValue() > 80) { System.Threading.Thread.Sleep(100 \* 60); } } } }
}
-
using System.Diagnostics;
namespace cpu_performance
{
internal class Class1
{static void Main(string\[\] args) { PerformanceCounter cpuCounter; PerformanceCounter ramCounter; cpuCounter = new PerformanceCounter { CategoryName = "Processor", CounterName = "% Processor Time", InstanceName = "\_Total" }; cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "\_Total"); ramCounter = new PerformanceCounter("Memory", "Available MBytes"); Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + "%"); Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB"); Console.WriteLine(); while (true) { System.Threading.Thread.Sleep(1000); DateTime localDate = DateTime.Now; Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + " %"); Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB"); Console.WriteLine("Local date and time: {0}, {1:G}", localDate.ToString(), localDate.Kind); Console.WriteLine(); if ((int)cpuCounter.NextValue() > 80) { System.Threading.Thread.Sleep(100 \* 60); } } } }
}
Few questions for you to think about 1. Which database - relational, graph, document? 2. What is the database design like - tables, columns, FKs etc. Then, find a suitable library which allows you to connect to the database and writes to it. For example if you choose SQL or any other relational database, you could make use of ADO.Net and write the database through dataset or direct queries.
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]
-
using System.Diagnostics;
namespace cpu_performance
{
internal class Class1
{static void Main(string\[\] args) { PerformanceCounter cpuCounter; PerformanceCounter ramCounter; cpuCounter = new PerformanceCounter { CategoryName = "Processor", CounterName = "% Processor Time", InstanceName = "\_Total" }; cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "\_Total"); ramCounter = new PerformanceCounter("Memory", "Available MBytes"); Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + "%"); Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB"); Console.WriteLine(); while (true) { System.Threading.Thread.Sleep(1000); DateTime localDate = DateTime.Now; Console.WriteLine("Computer CPU Utilization rate:" + cpuCounter.NextValue() + " %"); Console.WriteLine("The computer can use memory:" + ramCounter.NextValue() + "MB"); Console.WriteLine("Local date and time: {0}, {1:G}", localDate.ToString(), localDate.Kind); Console.WriteLine(); if ((int)cpuCounter.NextValue() > 80) { System.Threading.Thread.Sleep(100 \* 60); } } } }
}
1. Learn the basics of how databases work. Both design and actually using one. 2. Choose a database to use 3. Learn how C# interfaces with databases in general and specifically how the database in 2 works with C#. 4. Design a table that will hold the data. This follows from 1. 5. Put all of the above together.