Advertisement

10.04.2008 at 07:46PM PDT, ID: 23788101
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Does a variable take up a significant amount of space?  If so, can one be unloaded somehow once it is no longer necessary?

Asked by mrcoulson in C# Programming Language, Software/Systems Design

Tags:

I'm relatively new at programming.  I've pretty much jumped in without any formal training in programming foundations.  I'm beginning to get to a point where just knowing the syntax of a language is not enough.  I recently built an app in C# that checks for new entries in a database every four minutes.  I got curious about how much memory it takes up and decided to watch it for a while at work yesterday.  To speed things up, I changed my timer from four minutes to 4 seconds.  As I watched the Windows Task Manager, I saw my little app grow in memory usage about 2 K on every check.  Maybe 2 K doesn't seem like a lot, but I think it could be.  This is meant to run all day long on a fellow's computer and I can imagine that 2 K might grow to some much bigger number -- especially if he leaves his computer on overnight.

I've attached some code.  This is the block of code that runs every four minutes.  Here are my questions about it:

- Are there simple ways to make it more efficient?
- Can I unload or otherwise destroy all the variables and datasets at the end so I can give that memory back to the machine?
- Is there a way to optimize the timer?  I'm not sure why I think this, but it seems intuitive that this program probably eats up even more resources because it's always counting even when it seems that it's just sitting there.

Thanks for any help.  If you have advice or insight that's not necessarily C# related, I'll take it.  I want to understand better how code can be optimized for performance. Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
private void tmrCheck_Tick(object sender, EventArgs e)
        {
            // This opens the database.
            string conString = "Provider=Microsoft.Jet.OLEDB.4.0;"
            + "Data Source=\\\\DPR\\micromain_database\\msData_2.mdb";
            OleDbConnection msData_2Connection = new OleDbConnection(conString);
 
            // This creates the SELECT statement.
            string selectStatement = "SELECT MAX(Created) AS MaxOfCreated FROM tblWO";
 
            OleDbCommand objCmdSelect = new OleDbCommand(selectStatement, msData_2Connection);
            OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
            objAdapter1.SelectCommand = objCmdSelect;
            DataSet objDataset1 = new DataSet();
            objAdapter1.Fill(objDataset1);
 
            // This turns the result of the query into a string.
            string strResult = objDataset1.Tables[0].Rows[objDataset1.Tables[0].Rows.Count - 1]["MaxOfCreated"].ToString();
 
            // This turns the result of the query into a DateTime.
            DateTime dtResult = DateTime.Parse(strResult);
 
            // This sets a variable with the current time.
            DateTime dtToday = DateTime.Now;
 
            // This sets a variable for five minutes ago by subtracting 5 from dtToday.
            DateTime dtFiveMinutesAgo;
            dtFiveMinutesAgo = dtToday.AddMinutes(-5);
 
            // This compares dtResult to dtFiveMinutesAgo.
            if (dtResult > dtFiveMinutesAgo)
            {
                MessageBox.Show(this, "New work orders created!", "MicroMain Alert!", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
 
            // This prints the result in the textbox.
            textBox1.Text = strResult;
 
            // This prints the time of the check in the other textbox.
            DateTime dtNow = DateTime.Now;
            string strNow = dtNow.ToString();
            textBox2.Text = strNow;
 
            // This creates the SELECT statement for the asset.
            string selectStatement2 = "SELECT MAX(Asset) AS LastAsset FROM tblWO GROUP BY Created";
 
            OleDbCommand objCmdSelect2 = new OleDbCommand(selectStatement2, msData_2Connection);
            OleDbDataAdapter objAdapter2 = new OleDbDataAdapter();
            objAdapter2.SelectCommand = objCmdSelect2;
            DataSet objDataset2 = new DataSet();
            objAdapter2.Fill(objDataset2);
 
            // This turns the other query result into a string.
            string strResultAsset = objDataset2.Tables[0].Rows[objDataset2.Tables[0].Rows.Count - 1]["LastAsset"].ToString();
 
            //This prints that result in a textbox.
            textBox3.Text = strResultAsset;
 
            // Close the connection.
            msData_2Connection.Close();
 
        }
[+][-]10.04.2008 at 07:54PM PDT, ID: 22643204

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: C# Programming Language, Software/Systems Design
Tags: C#
Sign Up Now!
Solution Provided By: sunnycoder
Participating Experts: 2
Solution Grade: A
 
 
[+][-]10.04.2008 at 08:17PM PDT, ID: 22643261

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]11.02.2008 at 11:13AM PST, ID: 22862747

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]11.07.2008 at 07:39PM PST, ID: 22910765

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628