|
If the sensors are on different threads, the time they call BeginInvoke is not well defined in terms of order anyway. My question was about calling BeginInvoke multiple times from the same thread, and the order in which those invoked methods are run.
|
|
|
|
|
I've written an Outlook add-in that performs multiple jobs at the same time. Basically, I can highlight a stack of emails, right-click them, and tell the add-in to execute a standard process on SCCM objects with data contained in the emails.
The execution engine sets up a job object for each and every email in the list. Then, using the TPL, executes the entire stack of jobs, each job being a seperate task.
Well, each of those jobs can take about a minute to run. They report back status messages about what they are doing and what was and was not successful. Those status updates are setup by the task scheduler to execute on the UI thread where the DGV that shows the job queue state updates itself and shows the new data.
The goofy thing is that even though I can see the jobs executing and queueing up the status updates in a certain order (thank you VS2010!) those updates don't always execute in the same order they were queued up in. I haven't investigated why this occurs because, lets face it, it's just a status update. There's no pressing need for execution order here.
|
|
|
|
|
BobJanova wrote: How true is this?
Very.
Windows messages get collected in "event queues", and although they are called queues, the order of the elements isn't always maintained. It basically is, however there are certain exceptions, to name a few:
1. one can extract messages of a certain type, which basically means their type suddenly gets a higher priority; that is what the message filtering is about in e.g. GetMessage[^].
2. one can consolidate messages, e.g. Windows will postpone PAINT messages, and consolidate them into a single one if possible (which may enlarge the invalidation region). This normally is an optimization, as now fewer cycles are wasted on repainting an ever changing form.
|
|
|
|
|
Also be aware of any race conditions that may occur, and you may also get dead locks if you are not careful
|
|
|
|
|
Thanks, deadlocks is the main reason I've been investigating this approach!
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I'm hoping someone can help because I'm stumped here.
I have a DataGridView that is populated with a SQL query. For simplicity's sake, let's say the SQL query is as follows:
SELECT Name, Number, Lookup FROM ValuesTable
Now, depending on the value of the 'Lookup' column, the value in the 'Number' column can either be a straight forward value (when Lookup==0) or a reference to a different table (when Lookup==1), in which case I want a ComboBox in the cell which shows the various options in that other table.
In other words, I can't really use DataGridViewComboBoxColumn because not all cells in the column are ComboBoxes , only those for which the Lookup value is 1.
So far, so good. In the DataBindingComplete event handler of the DataGridView I have code similar to the following to put a ComboBox (and populate it) into the 'Number' cell of each row that has a value of 1 in the 'Lookup' cell.
foreach (DataGridViewRow row in myDataGridView.Rows)
{
if (row.Cells["Lookup"].Value.ToString() != "0")
{
DataGridViewComboBoxCell myComboCell = new DataGridViewComboBoxCell();
using (SqlCommand mySqlCommand = new SqlCommand("SELECT Number, Text FROM LookupTable"))
{
using (SqlDataReader mySqlDataReader = sqlCommand.ExecuteReader())
{
DataSet ds1 = new DataSet();
DataTable dt1 = new DataTable();
ds1.Tables.Add(dt1);
ds1.Load(mySqlDataReader, LoadOption.PreserveChanges, ds1.Tables[0]);
myComboCell.DataSource = ds1.Tables[0];
myComboCell.DisplayMember = "Text";
myComboCell.ValueMember = "Number";
}
}
row.Cells["Value"] = newCell;
}
}
This sort of works, but not quite. All the appropriate cells in the DataGridView has a ComboBox inside them and the options of the ComboBox are those retrieved from the Lookup Table. But when an option is selected in a ComboBox and the focus is moved away from that cell, the actual value displayed in the cell is the number by which the value was looked up.
Also, if the DataGridView is populated (like described above), all the cells with ComboBoxes show the number that is stored in the 'Number' field of ValuesTable, not the 'Text' field of LookupTable like myComboCell.DisplayMember = "Text" dictates.
I'd really appreciate if someone could set me straight here.
|
|
|
|
|
dear dewald
try this order
display member
value member
datasource
i hope it help you
|
|
|
|
|
Hello,
We have pdfs being displayed dynamically on the web. There are usually 7-9 pages, and each page has a different hyperlink to it.
Would like to click one link/button and have all those pdfs open in one window.
Any ideas?
Using sql server and C#
Thanks so much!
|
|
|
|
|
the only solution that I can see to this is to use an iframe[^].
is there a high/low as to how many you will open??
might be interesting to populate them in a gridview with each row being an iframe to the pdf document. then when you hover over the row you actually display the pdf in jQuery dialog or a lightbox of sort.
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
Hi,
I have a MFC app that I am porting to C#.NET.
The main window is a property sheet with three pages.
All three pages look almost exactly the same, the functionality is also 90% the same.
In MFC it was easy, I have an abstract base class (CBasePage) that inherits CPropertyPage, I then have three specialised classes (one for each page) that inherit CBasePage. Then I just create an instance of each specialised page and add them to the CPropertySheet.
Doing it this way, all the common stuff is in one place and I dont duplicate anything.
The problem is that with the CLR TabControl all the controls on the tabs are owned by the parent Form. I cant see any way of avoiding duplication of controls and functionality three times over.
Is there a nice OO way of doing this in C#.NET ?
Or, even a not so nice way ?
Thanks.
|
|
|
|
|
Put the common bits on a UserControl, derive from that, and stick it on a TabPage.
(In my opinion we should be able to design directly on a TabPage as easily as on a UserControl, but alas we can't. )
|
|
|
|
|
You can derive directly from TabPage, though you can't use the visual designer if you do that. I've done this in the past for a similar type of situation (a tab control of which every tab was a data sheet).
|
|
|
|
|
Yes, and I've done that too, but I want to design on it. I have tried using #if #else #endif , but most recently I gave up and did:
public partial class tpDataTable : System.Windows.Forms.TabPage
// public partial class tpDataTable : System.Windows.Forms.UserControl
to manually switch between base classes.
|
|
|
|
|
Haha, yeah, I've done that same thing in the past.
|
|
|
|
|
You could create your base class as a custom control from a UserControl, adding any common properties, methods, controls etc, and then create other custom controls that inherit from the base. Then you could just add a tab control to your form with your custom controls as controls inside each page.
Hope this helps
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
Thanks Guys,
I have created a UserControl and added it to each page no probs, I think it will do what I want now.
Thanks again.
|
|
|
|
|
A bit OT: this thread reminds me of a hack I once did where I had, for each TabPage in a WinForms TabControl, a set of Controls that had identical functionality in each TabPage (even if the controls did 'harvest' information unique to the TabPage they were inside).
In order to avoid duplicating them on each TabPage, I just put the controls in a UserControl, and inserted them ... as the user changed TabPages ... using the SelectedIndexChanged Event ... into the the currently visible TabPage.
Of course I did the right thing so that the Controls inside the UserControl were exposed, and could be accessed, and could have top-level event-handlers, etc.
Never quite decided if this was a clever hack, or just poor design
best, Bill
"Last year I went fishing with Salvador Dali. He was using a dotted
line. He caught every other fish." Steven Wright
|
|
|
|
|
When I tell a socket to "listen," what IP Address should I tell it to use?
When I use "netstat /a", it shows me the following possible local IP Addresses:
0.0.0.0
127.0.0.1
192.168.0.2 // This is the machine's address on my LAN
Which one should I use in the call to Bind ? (It accepts all of them)
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I think I figured it out. I should use IPAddress.Any .
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Always the best choice, unless you have multiple interfaces and you need to bind to an interface that has access to a particular network segment.
|
|
|
|
|
Richard Andrew x64 wrote: 127.0.0.1
I always thought that 127.0.0.1 would be localhost.
|
|
|
|
|
It is.
There's nothing preventing you from running the client and server on the same machine.
If the machine isn't connected to a network, the app still works.
|
|
|
|
|
Any address of the form 127.*.*.* is a loop back address.
|
|
|
|
|
This is the address I would use in your binding instance.
|
|
|
|
|
Richard Andrew x64 wrote: 0.0.0.0
That should basically say - use all network IPs to bind to. Which is only relevant if your computer has two network addresses. Which is more common if you have two network cards but might also be possible in other situations.
Richard Andrew x64 wrote: 127.0.0.1
Any address of the form 127.*.*.* is a loopback address. It will not exit the local machine.
Richard Andrew x64 wrote: 192.168.0.2
This is the address that that allows your computer to be addressed on a network. This is comparable to 0.0.0.0 except that it is specific to one network segment (only relevant if you have more than one.)
It is also a private network address. That in combination with firewalls/routers might or might not mean that using that address (or 0.0.0.0) would mean that your server is available from other locations on the private network. That address would never be visible outside (like the internet) the private network.
Typically for network exposure one should probably use a specific address and not use 0.0.0.0 because if there is more than one network segment then it is unlikely that exposing the server on both is the intent of the additional segments.
Allowing it the network address to be explicitly specified, via a configuration value, is probably a good idea.
|
|
|
|