|
I'm working on some client that collects information from testing station and inserts it to DB. Now i'm building a setup and i'm placing near the setup.msi some client.exe.config file with modified configurations. So the question is - is it possible somehow replace/update app.config file from external configuration file during the installation.
Thanks in advance.
|
|
|
|
|
It is. You will need to add a custom step to your installer that does this, but it's certainly possible.
|
|
|
|
|
I´m writing a communication library and have a threaded method listening for incoming data:
public partial class MCSerialPort
{
(SerialPort)port.DataReceived += DataReceivedHandler;
private async void DataReceivedHandler(object sender, SerialDataReceivedEventArgs args)
{
await ReadData();
}
private async Task ReadData()
{
await Task.Run(() =>
{
...
PackageReceived(this, new PackageReceivedEventArgs(package));
});
}
}
(MCSerialPort)port.PackageReceived += PackageReceivedHandler;
private void PackageReceivedHandler(object sender, PackageReceivedEventArgs args)
{
Package p = args.Package;
receivedRtb.Invoke((Action)delegate{receivedRtb.Text += p.ToString();} );
}
The thing is that when using this library in a "client" project the PackageReceived event handler method in the client (here the PackageReceivedHandler()) seems to be running on the same thread as the librarys ReadData() method, because I have to call Invoke() in this example in order to get the info into the receivedRtb RichTextBox. This complicates things slightly for the average library user, who might not think of having to write threadsafe code in the handler method. Is there any convenient way to make PackageReceivedHandler() run on the "main" thread?
|
|
|
|
|
TMattC wrote: the PackageReceivedHandler()) seems to be running on the same thread as the
librarys ReadData() method
Correct.
I think it's fine the way it is; the library should neither know nor care about the concerns of the calling application.
|
|
|
|
|
TMattC wrote: ... the PackageReceived event handler method in the client (here the PackageReceivedHandler()) seems to be running on the same thread as the librarys ReadData() method, because I have to call Invoke() ...
No, you have to call Invoke() because the PackageReceivedHandler isn't running on the UI thread.
There are various ways to raise the event on the UI thread - for example, using the SynchronizationContext class[^]. (It's All About the SynchronizationContext - MSDN Magazine[^])
However, since most libraries don't both doing this, most UI developers should be used to having to marshal the event handler code to the UI thread.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Label Clicked_Picture = new Label();
Random rnd = new Random();
List icons = new List()
{
"!", "!", "N", "N", ",", ",", "k", "k",
"b", "b", "v", "v", "w", "w", "z", "z"
};
private void Form1_Load(object sender, EventArgs e)
{
Random rnd = new Random();
int i = rnd.Next(icons.Count);
for (i = 0; i < icons.Count; i++)
{
Clicked_Picture.Tag = icons[i];
}
}
modified 11-Feb-15 7:59am.
|
|
|
|
|
You'd need to "Create" labels, and add them to the controls-collection of the form in order to get some labels on the form.
for (i = 0; i < icons.Count; i++)
{
Label l = new Label () { Dock = DockStyle.Top };
this.Controls.Add(l);
l.Text = icons[i];
} I've changed it from "tag" to "text", so you can see what character from the list is being loaded into the label. The "tag" property itself does not change the appearance of a label. Take note that "l" is a local variable; it won't be used outside the constructor, limits the scope and is preferable over a member-variable in this scenario.
Further, you'd only need a single random; at the moment you're creating a rnd-object in two separate places. Lastly; if you want pictures, then a PictureBox control may be preferable over a Label.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for answering. I do have 16 labels already on the form and What I'm doing is a picture matching game with wingding symbols on the text AND the tag properties. So when i click on the label it shows the tag property. Everything works except loading random wingdings in the tag properties. This code handles the clicked picture:
private void Picture_Click(object sender, EventArgs e)
{
if (tmr_Delay.Enabled == true)
return;
Clicked_Picture = (Label)sender;
Clicked_Picture.Enabled = false;
Number_of_Images++;
if (Number_of_Images < 3)
{
Clicked_Picture.Text = Clicked_Picture.Tag.ToString();
if (Number_of_Images == 1)
{
Temp_Tag = Clicked_Picture.Tag.ToString();
Temp_Pic = Clicked_Picture;
}
else
{
if (Temp_Tag != Clicked_Picture.Tag.ToString())
{
tmr_Delay.Enabled = true;
}
else
{
Num_Correct++;
lbl_Matches.Text = Num_Correct.ToString();
if (Num_Correct == 8)
{
timer1.Stop();
MessageBox.Show("Congratulations, all matches complete! \nYou completed the game in " + mins + "m " + secs + "s");
txtUsername.Visible = true;
button1.Visible = true;
lblusername.Visible = true;
lblprompt.Visible = true;
}
}
Number_of_Images = 0;
}
}
}
|
|
|
|
|
Ah, that's because it is not assigning the values it reads correctly. If you use my version, it'll put it in the tags of the controls that are created in that method - but won't hook up the clicked method.
It is below line that assigns the content of the list;
Clicked_Picture.Tag = icons[i];
It is assigned to a "New Label" in the original code. It should point to one of the existing labels. Try looking for one of the existing labels in the constructor, before assigning the value to the tag-property.
Clicked_Picture = this.Controls.Find(string.Format("Label{0}", i), true).FirstOrDefault() as Label;
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks for your help. What i did in the end was put the labels into a groupbox and assign random locations
List points = new List();
private void Form1_Load(object sender, EventArgs e)
{
foreach (Label label in groupBox1.Controls)
{
points.Add(label.Location);
}
foreach (Label label in groupBox1.Controls)
{
int next = rnd.Next(points.Count);
Point p = points[next];
label.Location = p;
points.Remove(p);
}
modified 11-Feb-15 7:59am.
|
|
|
|
|
|
I use below code to reach the autocomplete in a textbox. But the chance is once, it cannot keep in autocomplete status. When I finish an autocomplete work, and then I cannot key in another autocomplete word. Does somebody know how to let textbox always keep in autocomplete?
private void Form1_Load(object sender, EventArgs e)
{
var source = new AutoCompleteStringCollection();
source.AddRange(new string[]
{
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
});
var textBox = new TextBox
{
AutoCompleteCustomSource = source,
AutoCompleteMode =
AutoCompleteMode.SuggestAppend,
AutoCompleteSource =
AutoCompleteSource.CustomSource,
Location = new Point(20, 20),
Width = ClientRectangle.Width - 40,
Visible = true
};
Controls.Add(textBox);
}
modified 10-Feb-15 8:18am.
|
|
|
|
|
I think your problem is that the text isn't highlighted when you go back into the textbox, so any characters you start to type are appended to what is already there - hence auto-complete does not work.
The solution is to highlight all of the text as you enter the textbox: Add this line just before you add textbox to the Controls collection
textBox.Enter += new System.EventHandler(this.textBox_GotFocus);
and add this method to the form
private void textBox_GotFocus(object sender, EventArgs e)
{
((TextBox)sender).SelectAll();
}
Unfortunately when you use the mouse to enter the field the caret is positioned wherever the mouse pointer is so the MouseEnter method doesn't work in quite the same way as we'd like.
To get over that you can use the MouseClick event:
textBox.MouseClick += new System.Windows.Forms.MouseEventHandler(this.textBox_MouseClick); and add this method
private void textBox_MouseClick(object sender, MouseEventArgs e)
{
((TextBox)sender).SelectAll();
}
|
|
|
|
|
Hello CHill60! Thanks your answer. But my problem is that I cannot input the second word with Autocomplete list item. For example, when I input "May Apr", it should be disapeear "May April" for me to select "April". Now it just can work in frist word "May".
|
|
|
|
|
That's because May April is not part of the autocomplete list - you'll either have to ensure that all combinations are in the autocomplete list, or write a user control to do that - I'll have another look
|
|
|
|
|
I am working on repeater I use the check box control in header and tbody i want when i check the header check box the all check boxes which is in body checked some body help me how is possible.
|
|
|
|
|
You just asked the same question yesterday - got some answers too...If those answers are not good for you than add details and ask for more info, but asking the same question over and over again is not a good way to getting answers...
Skipper: We'll fix it.
Alex: Fix it? How you gonna fix this?
Skipper: Grit, spit and a whole lotta duct tape.
|
|
|
|
|
Hi!
I have defined an event in a certain class:
public class BrokenPackageReceivedEventArgs : EventArgs
{
private readonly byte[] package;
public byte[] Package { get { return package; } }
public BrokenPackageReceivedEventArgs(byte[] _package) { package = _package; }
}
public event EventHandler<BrokenPackageReceivedEventArgs> BrokenPackageReceived;
BrokenPackageReceived(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray()));
It seems that if no method is added to the event, it throws a NullReferenceException. I dont want that exception to occur, in fact I am baffled it actually does occur. Is this really the way events always do if no method is attached? Should I just use a try-catch with an empty catch to get rid of it, or am I missing something?
|
|
|
|
|
I just realized I can do like this:
if(BrokenPackageReceived != null)
BrokenPackageReceived(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray()));
Is this the common way to do it?
|
|
|
|
|
Yes it is. And you could improve it a bit further by making a copy of it before you check it for null:
var copy = BrokenPackageReceived;
if(copy != null)
copy(this, new .....);
..because theoretically some subscriber could unsubscribe during the execution of the null-check.
edit: to clarify, not some subscriber but the last subscriber
|
|
|
|
|
Rather than doing this, try this:
var handler = BrokenPackageReceived;
if (handler != null)
{
handler(this, new BrokenPackageReceivedEventArgs(dataLst.ToArray());
} The reason you will want to do this is that there's a potential race condition because it's possible for BrokenPackageReceived to have a value when you check it, and then be null when you attempt to call it.
|
|
|
|
|
I have set .net Trust level to medium from Full. Its not allowing me to upload file .
can i change web config trust level to full at the same time when i set .net trust level to medium in IIS.
Will it effect IIS settings and fulfill the purpose of medium trust level.
i go through many articles somewhere its written to allow permission and somewhere set to full in web config.
its showing this error when my project is deployed in root folder else working fine .
Please Help.
Thanks
-- modified 11-Feb-15 0:31am.
|
|
|
|
|
Hello everyone,I have given a million records in sql server and asked apply the Jaro - winkler algorithm to find the dupes in those records and I wanted to do it using c#.net. Could anyone help me if you already did such kind of job.I am a fresher so I need some little help in doing it. I would appreciate for your valuable help .
|
|
|
|
|
Help with what exactly?
If you were looking for someone to just hand over their code, you've come to the wrong site.
|
|
|
|
|