|
Hi Alan,
thanks for your reply!
At the moment I really make use of a combination of EnumWindows and GetWindowThreadProcessId to get my own (hidden) window's handle within the console application. But I am not happy about enumerating over all windows.
FindWindow was also my first thought... the problem was that I had no clue what the title is. The shell usually shows the console application's full path in the title. Having multiple instances running, this can be quite difficult to find a specific one.
But you made me think about the window title again, because you really hardcoded a title for a console application. First I thought I could not change it from within the console application itself in C#, since MainWindowTitle is read-only. But then I found the following API method:
[DllImportAttribute("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern bool SetConsoleTitle(IntPtr lpConsoleTitle);
In this case I can easily set the window title; either by passing it as parameter along with ProcessStartInfo , or simply generating it within the console itself.
Thanks for thought-provoking impulse.
Cheers,
Roland
|
|
|
|
|
If your GUI app crashes, I see no way for it to even try to do this beforehand.
Are you also developing the console apps? If so, maybe the console app can monitor the existence of the GUI app and hide and reshow itself on its own?
|
|
|
|
|
Yes, we create both, the GUI and the Console Apps. The latter one can be executed manually or started through the UI (invisible).
So we are actually realy monitoring the UI, but had no (good) idea how to make the console show itself when the GUI was gone.
But as a result of Alan's thought-provoking impulse I have an idea how to do this now.
Cheers, Roland
|
|
|
|
|
I have been looking all over for an answer to this question and can't find something that fits exactly what I am trying to do.
I have a DataGridView that is bound to a DataTable, which is part of a strongly typed DataSet from a SQL Server DB. I can manually update the DataGridView fine. However, my program has multiple threads, one of which adds and removes rows of the underlying data in the DataTable to which the DataGridView is bound. This itself works ok sometimes, but at other times I receive the following exception:
Exception in DataGridView: System.IndexOutOfRangeException: Index 9 does not have a value at System.Windows.Forms.CurrencyManager.get_Item(Int32 index) at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetError(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex)
To replaces this default dialog please handle the DataError event.
I have written test code and have confirmed that the problem seems to arise because the DataTable is being changed on a different thread. When I add/remove rows on the GUI thread, all is fine. But when I add/remove rows from a different thread, I get the Exception.
I have tried to use the Delete method rather than the Remove method in the DataTable class, but that does not seem to make a difference. And for purposes of my program, it is highly undesirable to change the structure of the program so that the GUI thread makes the changes to the DataTable. I suppose an option might be to catch the DataError exception and do nothing with it, but that is really a last resort. Please help here!
|
|
|
|
|
Hi,
1. please don't apply PRE tags to text. PRE tags is for special formatting, it applies to code snippets, and tabular data, not regular text.
2. you shouldn't read and write data structures in general from more than one thread without proper locks. Adding/removing a row in a DT or a DGV may (and probably always will) render the internal state invalid for as long as the update takes, so another thread reading it would get confused, obtain wrong data, and maybe even hang. I see basically three ways to resolve your problem:
a) use real locks; as one of the interested parties is the main thread (which displays the DGV for you), this is a no-no, as you shouldn't keep the main thread waiting at all.
b) tell the other thread to have the updates delegated to the main thread; there are at least two ways to get that done:
b1) with Control.Invoke, see this little article[^];
b2) with BackgroundWorker.ReportProgress, which probably is most appropriate for your situation.
c) use two DataTables: one that gets displayed (by the main thread), and one that gets calculated (by the background thread); when the calculation finishes, have the main thread display the new DT rather than the old one. "ping-pong".
Luc Pattyn [My Articles] Nil Volentibus Arduum
modified on Thursday, September 15, 2011 10:52 PM
|
|
|
|
|
Hi All, I need to retrive value of GridView slelected row cell value.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
AllowSorting="True" >
<Columns>
<asp:BoundField HeaderText="First" DataField="RecNo"/>
<asp:BoundField HeaderText="Second" DataField="DecFN"/>
<asp:BoundField HeaderText="Third" DataField="DecLN"/>
<asp:BoundField HeaderText="Fourth" DataField="DOC"/>
<asp:BoundField HeaderText="Fifth" DataField="UserID"/>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="Button1" runat="server" CausesValidation="false" Text="Edit" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" CausesValidation="false" Text="Print" OnClick="Butoon2_Click"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="#DDFFEE" />
</asp:GridView>
If I click on button1 or Button2 I want to retrive value of a specefic cell value
thanks,
|
|
|
|
|
Add a CommandName property to your buttons like this.
<asp:Button ID="Button1" runat="server" CausesValidation="false" Text="Edit" OnClick="Button1_Click" CommandName="Button1Command"/>
And then handle the RowCommand event. See below
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Button1Command")
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = GridView1.Rows[index];
}
}
Signature construction in progress. Sorry for the inconvenience.
|
|
|
|
|
hi,
I have below code. how do I replace with regular expression or much sipler to this.?
many thanks
if(!identier.StartsWith("L#")
identifier.Replace(something,"");
if(!identier.StartsWith("X#")
identifier.Replace(something,"");
if(!identier.StartsWith("G#")
identifier.Replace(something,"");
|
|
|
|
|
Looking at your example, the "pattern" that "jumps out at me" is that in each case you are using the first two characters of (what I assume is the string) 'identifier.'
That suggests, to me, a switch/case statement using the first two characters of the 'identifier' string as the 'match' criterion.
But, if your 'heart is set' on a RegEx solution, don't let me deter you
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
it was my mistake..yes...identifier is a string type.
|
|
|
|
|
You can't - your code is wrong, on a number of levels.
Firstly:
if(!identier.StartsWith("L#")
identifier.Replace(something,""); Is incomplete - the if condition is never terminated (you need a ')' in there.
(Assuming you fix that) Secondly:
If identifier starts with "L#" then it won't start with "X#". So, your replace operation will be called by at least one of the first two if conditions, and then always by the third.
(Assuming you fix that) Thirdly:
Strings in .NET are immutable - they cannot be changed - so string.Replace does nothing at all to identifier, but instead generates a new string, which you then discard.
As a result, your entire code block as shown can be replaced by nothing, as it has no effect whatsoever on subsequent code! You don't need a regex for that!
Think again what you are trying to do, and perhaps explain to us what results you are expecting, becauae that is not going to give them to you.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Certainly your first point and conclusion are correct, but the other points assume a String , which may not be a safe assumption. identifier may be a StringBuilder (for instance*) and the StartsWith method may be an Extension Method -- we just don't know, not enough information was provided.
If in fact your third point is incorrect, and identifier is mutable, then your second point is also not valid.
Having said that, I wouldn't bet against your being absolutely correct on all points.
* It could also be some other unknown class.
|
|
|
|
|
I agree with you completely - it's just Occam suggests my answer, given the code quality of the whole fragment
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
+5 for bringing in my favorite "razor," William of Ockham, as well as, of course, a good, solid, technical answer.
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
+5 for acute analysis thoroughly applied ! best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
my requirement is if a string starts with "L#",or "G#" or "X#" i dont want to replace some part of the string. Otherwise I will replace.
for example: string identifier="L#1234";
In this case I dont want to replace any thing there. Otherewise I would replace some part of the string there.
|
|
|
|
|
Then why worry about using a regular expression? There's no need to do this - sometimes it's just easier to directly manipulate a string - in this case, if the second character isn't hash then you don't need to check the first character.
|
|
|
|
|
got it..thanks. sometimes we think too much for simple ones.
|
|
|
|
|
It depends on the declaration of identifier. Assuming it is a string, here is my shortest replacement:
new System.Text.RegularExpressions.Regex(identifier.ToString());
Others already explained why it does the same your code does.
And yes, the ToString() part is necessary.
|
|
|
|
|
Luc Pattyn wrote: And yes, the ToString() part is necessary.
Ummm... what?
|
|
|
|
|
Exactly what I said.
|
|
|
|
|
I have a partial class that extends my property class, which is a table provided by the entity framework. I am extending that class to supply a string that contains a full address from address parts (number, street name, etc...)
It looks like this, in brief:
public partial class Property
{
public string fullAddress
{
get
{
string address = this.number.ToString();
if (!string.IsNullOrEmpty(this.direction))
{
address += " " + this.direction;
}
return address;
}
}
}
When I type this. Intellisense gives me the option to use direction or _direction. What is the difference and which should I use for getting?
I know I have read this somewhere before but it has slipped my mind.
Cheers, --EA
|
|
|
|
|
Where and how is the variable (or is it a Property ?) 'direction' defined ? Is '_direction' defined anywhere in your code ? best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
It is not defined anywhere in my code. I assume it is an auto generated item from the edmx, but I don't know for certain.
Cheers, --EA
|
|
|
|
|
I was asking about 'direction' and '_direction' used in your code. I'm a little confused by this thread's title which speaks of 'number' and '_number.'
The immediate 'hypothesis' is that '_direction' is a private backing field for a Property somewhere named 'direction;' but, if that's true, how does it get exposed at this point in your code ?
You might clarify in this code example what object 'this' is a reference to ?
Are you dealing with 'black box' code here you can't use the Object Browser in VS Studio on ?
Wish I could help, but my psychic powers are dimmer every day.
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|