|
Not unless the display must be updated within a very short time of the map update (e.g. well under 1 second).
What you need is some sort of event that notifies the GUI thread that an update has occurred. The GUI thread may then (in its own good time) take a "snapshot" of the data, and process it. Note that this is an event like any other, so it should fit nicely into the event-driven model used by the GUI thread.
Assuming that any single update of the map does not consume too much processor time, this will appear transparent to the user. At most, the display will lag slightly behind the updates if many updates are to be performed at the same time.
If you use blocking synchronization, the trick is to ensure that (a) the writing thread does not block the GUI thread for too long, and (b) that neither thread crashes while holding the lock. If you use "lock-free" methods, these problems go away.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
One way is to put your worker thread in an infinite loop of sorts, kind of like a thread pool would. The loop needs to have clear paths to terminate the thread in any event.
You'll also need to use Wait Handles
class ControllableThread
{
Thread _thread;
Action _task;
bool _shutdown;
ManualResetEvent[] _resetEvents
public void ThreadProc()
{
while (!_shutdown)
{
WaitHandle.WaitAny(_resetEvents);
if (_task != null)
{
_task();
}
}
}
}
Now this example is an oversimplification but it can point in the right direction. The Wait Handles act as crossing guards that allow the thread to execute whatever method is set to the _task variable and hold the thread's execution until their state is changed.
|
|
|
|
|
Starting out, I would wonder why the "list" needs to be "sorted" once created.
If the requirement is for an "ordered list", and items are added dynamically, then I would look at adding / inserting items "in order".
There are classes for "sorted lists" and lists where items can be added / inserted in any order and therefore do not need "sorting" afterwards.
Having eliminated the need to sort the list when new items are added, the problem becomes simpler.
|
|
|
|
|
Can anyone explain what this code is doing, got this code from codeproject - how this is cponnectipon tpo database?
namespace WindowsFormsApplication2
{
partial class Form1
{
///
/// Required designer variable.
///
private System.ComponentModel.IContainer components = null;
///
/// Clean up any resources being used.
///
/// <param name="disposing" />true if managed resources should be disposed; otherwise, false.
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.dataGridView2 = new System.Windows.Forms.DataGridView();
this.cboX = new System.Windows.Forms.ComboBox();
this.cboY = new System.Windows.Forms.ComboBox();
this.cboZ = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.txttNullValue = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.chkSumValues = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
this.SuspendLayout();
//
// dataGridView1
//
this.dataGridView1.AllowUserToOrderColumns = true;
this.dataGridView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView1.Location = new System.Drawing.Point(0, 23);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.Size = new System.Drawing.Size(274, 491);
this.dataGridView1.TabIndex = 0;
//
// dataGridView2
//
this.dataGridView2.AllowUserToOrderColumns = true;
this.dataGridView2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView2.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView2.Location = new System.Drawing.Point(3, 156);
this.dataGridView2.Name = "dataGridView2";
this.dataGridView2.Size = new System.Drawing.Size(284, 355);
this.dataGridView2.TabIndex = 2;
//
// cboX
//
this.cboX.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cboX.FormattingEnabled = true;
this.cboX.Location = new System.Drawing.Point(74, 8);
this.cboX.Name = "cboX";
this.cboX.Size = new System.Drawing.Size(87, 21);
this.cboX.TabIndex = 3;
//
// cboY
//
this.cboY.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cboY.FormattingEnabled = true;
this.cboY.Location = new System.Drawing.Point(74, 35);
this.cboY.Name = "cboY";
this.cboY.Size = new System.Drawing.Size(87, 21);
this.cboY.TabIndex = 4;
//
// cboZ
//
this.cboZ.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.cboZ.FormattingEnabled = true;
this.cboZ.Location = new System.Drawing.Point(74, 62);
this.cboZ.Name = "cboZ";
this.cboZ.Size = new System.Drawing.Size(87, 21);
this.cboZ.TabIndex = 5;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 11);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(52, 13);
this.label1.TabIndex = 6;
this.label1.Text = "Column X";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(13, 35);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(52, 13);
this.label2.TabIndex = 7;
this.label2.Text = "Column Y";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(13, 62);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(52, 13);
this.label3.TabIndex = 8;
this.label3.Text = "Column Z";
//
// button1
//
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Location = new System.Drawing.Point(173, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(114, 78);
this.button1.TabIndex = 9;
this.button1.Text = "update";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// splitContainer1
//
this.splitContainer1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.splitContainer1.Location = new System.Drawing.Point(12, 15);
this.splitContainer1.Name = "splitContainer1";
//
// splitContainer1.Panel1
//
this.splitContainer1.Panel1.Controls.Add(this.label5);
this.splitContainer1.Panel1.Controls.Add(this.dataGridView1);
//
// splitContainer1.Panel2
//
this.splitContainer1.Panel2.Controls.Add(this.label6);
this.splitContainer1.Panel2.Controls.Add(this.chkSumValues);
this.splitContainer1.Panel2.Controls.Add(this.label4);
this.splitContainer1.Panel2.Controls.Add(this.txttNullValue);
this.splitContainer1.Panel2.Controls.Add(this.label1);
this.splitContainer1.Panel2.Controls.Add(this.button1);
this.splitContainer1.Panel2.Controls.Add(this.dataGridView2);
this.splitContainer1.Panel2.Controls.Add(this.label3);
this.splitContainer1.Panel2.Controls.Add(this.cboX);
this.splitContainer1.Panel2.Controls.Add(this.label2);
this.splitContainer1.Panel2.Controls.Add(this.cboY);
this.splitContainer1.Panel2.Controls.Add(this.cboZ);
this.splitContainer1.Size = new System.Drawing.Size(568, 514);
this.splitContainer1.SplitterDistance = 274;
this.splitContainer1.TabIndex = 10;
//
// txttNullValue
//
this.txttNullValue.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txttNullValue.Location = new System.Drawing.Point(74, 87);
this.txttNullValue.Name = "txttNullValue";
this.txttNullValue.Size = new System.Drawing.Size(87, 20);
this.txttNullValue.TabIndex = 10;
this.txttNullValue.Text = "-";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(13, 87);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(55, 13);
this.label4.TabIndex = 11;
this.label4.Text = "Null Value";
//
// chkSumValues
//
this.chkSumValues.AutoSize = true;
this.chkSumValues.Location = new System.Drawing.Point(74, 113);
this.chkSumValues.Name = "chkSumValues";
this.chkSumValues.Size = new System.Drawing.Size(82, 17);
this.chkSumValues.TabIndex = 13;
this.chkSumValues.Text = "Sum Values";
this.chkSumValues.UseVisualStyleBackColor = true;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(3, 0);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(44, 13);
this.label5.TabIndex = 1;
this.label5.Text = "Source:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(16, 137);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(40, 13);
this.label6.TabIndex = 14;
this.label6.Text = "Result:";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(592, 541);
this.Controls.Add(this.splitContainer1);
this.Name = "Form1";
this.Text = "Pivot Table";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGridView2)).EndInit();
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel1.PerformLayout();
this.splitContainer1.Panel2.ResumeLayout(false);
this.splitContainer1.Panel2.PerformLayout();
this.splitContainer1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.DataGridView dataGridView1;
private System.Windows.Forms.DataGridView dataGridView2;
private System.Windows.Forms.ComboBox cboX;
private System.Windows.Forms.ComboBox cboY;
private System.Windows.Forms.ComboBox cboZ;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox txttNullValue;
private System.Windows.Forms.CheckBox chkSumValues;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Label label6;
}
}
namespace PivotTable
{
public partial class Form1 : Form
{
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
dt.Columns.Add("EmployeeID", Type.GetType("System.String"));
dt.Columns.Add("OrderID", Type.GetType("System.Int32"));
dt.Columns.Add("Amount", Type.GetType("System.Decimal"));
dt.Columns.Add("Cost", Type.GetType("System.Decimal"));
dt.Columns.Add("Date", Type.GetType("System.String"));
dt.Rows.Add(new object[] { "Sam", 1, 25.00, 13.00, "01/10/2007" });
dt.Rows.Add(new object[] { "Sam", 2, 512.00, 1.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Sam", 3, 512.00, 1.00, "03/10/2007" });
dt.Rows.Add(new object[] { "Tom", 4, 50.00, 1.00, "04/10/2007" });
dt.Rows.Add(new object[] { "Tom", 5, 3.00, 7.00, "03/10/2007" });
dt.Rows.Add(new object[] { "Tom", 6, 78.75, 12.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Sue", 7, 11.00, 7.00, "01/10/2007" });
dt.Rows.Add(new object[] { "Sue", 8, 2.50, 66.20, "02/10/2007" });
dt.Rows.Add(new object[] { "Sue", 9, 2.50, 22.00, "03/10/2007" });
dt.Rows.Add(new object[] { "Jack", 10, 6.00, 23.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Jack", 11, 117.00, 199.00, "04/10/2007" });
dt.Rows.Add(new object[] { "Jack", 12, 13.00, 2.60, "01/10/2007" });
dt.Rows.Add(new object[] { "Jack", 13, 11.40, 99.80, "03/10/2007" });
dt.Rows.Add(new object[] { "Phill", 14, 37.00, 2.10, "02/10/2007" });
dt.Rows.Add(new object[] { "Phill", 15, 65.20, 99.30, "04/10/2007" });
dt.Rows.Add(new object[] { "Phill", 16, 34.10, 27.00, "02/10/2007" });
dt.Rows.Add(new object[] { "Phill", 17, 17.00, 959.00, "04/10/2007" });
dataGridView1.DataSource = dt;
foreach (DataColumn dc in dt.Columns)
cboX.Items.Add(dc.ColumnName);
foreach (DataColumn dc in dt.Columns)
cboY.Items.Add(dc.ColumnName);
foreach (DataColumn dc in dt.Columns)
cboZ.Items.Add(dc.ColumnName);
}
private void button1_Click_1(object sender, EventArgs e)
{
try
{
string x = "";
string y = "";
string z = "";
if (cboX.SelectedItem != null)
x = cboX.SelectedItem.ToString();
if (cboY.SelectedItem != null)
y = cboY.SelectedItem.ToString();
if (cboZ.SelectedItem != null)
z = cboZ.SelectedItem.ToString();
DataTable newDt = new DataTable();
if (y != "" && z != "")
newDt = PivotTable.GetInversedDataTable(dt, x, y, z, txttNullValue.Text, chkSumValues.Checked);
else
newDt = PivotTable.GetInversedDataTable(dt, x, y);
dataGridView2.DataSource = newDt;
}
catch(Exception err)
{
MessageBox.Show("Error: " + err.Message);
}
}
}
}
|
|
|
|
|
why dont you ask this question at the bottom of the CP Article you took this from - its a better way than asking a general question here, like you've done ... that way, (hopefully) the author of the article may be able to help you.
As it is, your question is a bit broad in scope - I can suggest on a cursory glance that a winforms GUI is being used, to display a 'hard loaded' datatable in a grid, and a pivot table operation is being performed when a button is clicked - the result of the pivot operation seems to be going to a different grid. But really, you need to find some good c# books and read lots if you're having trouble with this - download the article, play with it, search and read, modify, do it yourself - thats the only way to understand it
btw >> Quote: how this is cponnectipon tpo database? its not connected to a database - the data is being populated in the Quote: Form1_Load event handler
|
|
|
|
|
Your question seems pretty fishy... Why would anyone post in their article the code for the Form's design (InitializeComponent)?
Can you link us to the original article?
Also, indeed, the question should be asked in the article itself.
Best,
John
|
|
|
|
|
And nobody is going to explain code to you line by line.
Do you have any idea how much work explaining code line by line is?
Every single line needs a paragraph of explanation! For example:
int next = r.Next();
Create a new variable called "next" which can hold a integer value. From the previously declared Random instance "r", call the "Next" method to get a new random number, and assign it to the "next" variable.
Can you imagine how long it would take us to explain even a very short code fragment, let alone the whole of a form like your example, line by line?
No. It is not going to happen. If you have a specific problem, then ask a question about it. But think first - would you want to sit down for 45 minutes and type up a line-by-line description for no good reason?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Put break-points at strategic places in the code, then single-step (F11 in Visual Studio) through the code at run-time observing what happens, what the values of variables are.
When you reach an understanding of where the code is not in a state that you expect, then:
1. ask the author of the article a specific question
2. or, ask a question here
Whereever you ask, post only the code that is relevant to what you do not understand, or what creates an error, etc.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Hello,
when i use chart control to refresh data, i use RecalculateAxesScale() command to refresh axis value.
But ,one status and other status Axis label is not at the same position when refresh, it offset.
I set ChartArea position and innerplot postion,but i don't know why axisA label can be up and down offset.
|
|
|
|
|
|
VirtualQueryEx(processHandle, proc_min_address, out mem_basic_info, 28);
|
|
|
|
|
Is the number #28 what you calculate as the memory footprint of the Struct ? If so, I guess that's not the right size.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
how do I get the correct size?
|
|
|
|
|
You get the right size by:
1. studying the MS documentation for memory allocation by Type + the overhead for a Struct object
2. and/or you do a some research on inter-op with NotePad; there's content here on CP.
3. you take a working example of inter-op with NotePad and study its code.
4. you look up the Win API calls you are making and study them carefully
You can do this: with some effort
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
what would be the right size for a notepad for example?
|
|
|
|
|
how do I get the correct size?
|
|
|
|
|
The last parameter (the one you use 28 in place) should look like this:
(uint)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION))
|
|
|
|
|
changed evil is still return 0 !!in basic_info !!when I moved 28 to 100 come some values but not complete!!
|
|
|
|
|
Take a look at the code here[^]
|
|
|
|
|
I work!! compile for Win32 and worked do not know 'cause for win64 was giving erro
|
|
|
|
|
what might be going wrong?
|
|
|
|
|
Hi everyone,
First of all apologise for any english mistake as english is not my natural language.
Problem to Solve:
I need to import data from 3 flat files. It might be a 4 one. The files will be very similar in structure. I mean the data contained in the files are very similar in structure. In these files each line represents a record to imported into an object object. The way to process the file is the same for all files. Each line represents a new record and each file has a related file that tells you which bit in the line to extract and the length of that bit. These fetched bit represent properties in C# objects.I'm thinking in reading the files line by line returning a String and per string will use the related file to extract the necessary/right info and export the data into an object.
I would like help with the following:
1) Which structure should I use store the static (maybe constant) information in the related files used to fetch the right bits of info from the returned strings.
2) How should I design the class library responsible for all this process in terms of classes, interfaces...maybe a "factory"
Many thanks.
|
|
|
|
|
A key question here (to me) is whether you created this format, and have the "rights" to select/implement another strategy, or whether you have to use this format.
I say this because I hypothesize that whatever you are doing here could be done with standard serialization/deserialization techniques using .NET WCF (DataContract, DataMember), and result in more maintainable, less elaborate, code ... without any major penalty in terms of memory consumption, file-size, etc.
Having a set of files where each file has an associated "schema" file to be used for parsing the data in the file, is an okay choice ... depending.
Your mention of "records" suggests this is a database app, but your speaking of "imported into an object" and "These fetched bit represent properties in C# objects" suggest this is more a problem involving deserialization.
Please clarify your question further.
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
|
|
|
|
|
Hi BillWoodruff,
Thanks for answering.
I do not have the right to implement another strategy. I have to use the formats provided. if they will change in the future I do not know. The format of the files, the files containing data and their associated schemas, will be sent from a "third party" system. The files Will have a fixed structure. Base on the associated schemas I need to parse each line.
When I say "records" I mean an entity. Each line of the file represents and entity. Let say that each line represents the entity Person. And based on the associated schema files I will parse the line to get the age, name, gender, etc.... Then I will create an instance of the object Person with this fetched data. Later everything will be stored in a database.
Hope this helps to clarify.
Any doubt please just let me know.
Many thanks for help.
|
|
|
|
|
I have to deploy my project from local to the server,in local it works fine but the problem when I try to drop the database "sma" and recreate it,I get this error:
"Message":"An error has occurred.","ExceptionMessage":"String was not recognized as a valid DateTime.","ExceptionType":"System.FormatException","StackTrace":" at System.DateTime.Parse(String s)\r\n at SMA.Entities.Models.SMADBInitializer.Seed(SMAContext context)\r\n at System.Data.Entity.DropCreateDatabaseAlways`1.InitializeDatabase(TContext context)\r\n at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)\r\n
I work on rest API service with asp.net MVC5,it works fine and the database was created with the tables in local(xampp),but I get this error in the server (Windows Server 2012),many tables are created but others not !! I don't know why did I miss any thing
thanks a lot for help
|
|
|
|
|