|
Hello everybody!
I would like to know how can I publish an application with VS2005 to make it works not only for a single local user purpose.
After installation I can launch my application on local computer only from current (which has installed) user account. But I need this application to be available for any local user account.
Thanks in advance.
Igor Zenyuk
|
|
|
|
|
How to change a label text or disable a button on a Web Form application from a thread. Is it possible in managed C# as it produces error that you can not access Form components from another thread compared to managed C++ Windows Forms
chesnokov
|
|
|
|
|
You can't access controls directly from a thread. Because controls are in another thread. You need to use delegates for this. Use the InvokeRequired property to identify the threads are different. According to that make calls. Check this MSDN[^] article for more idea.
BTW, you can use ReportProgress enabled BackGroundWorker class, which provides inbuilt support for all these.
|
|
|
|
|
I have an application in that all conncetion string are in config files ..
so what i need to do to use all those values what ever in the config files...
Thanks alot..
T@SU
|
|
|
|
|
erm... look them up in the config file ? If you're looking them up all through your code, then your code is ultimately broken, as it clearly is mixing it's data layer code throughout the app.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
No what i am asking here i have config file/debug folder...
that contain some field like "connectionString"
so i have to use this connectionStringin my C# code so how can i use... i need to read this config file or anyother way to do so..
Thanks for your reply...
T@SU
|
|
|
|
|
Check out System.Configuration.
|
|
|
|
|
Microsoft's Best Practices guide says two things:
1. always validate enum values passed to a method
2. don't use IsDefined, as it forces a metadata lookup and can impact performance
They recommend using a range to validate the enum (ie, less than Days.Monday, greater than Days.Sunday, etc).
However, I'm using enums where the values aren't necessarily contiguous.
So, without using Enum.IsDefined(typeof(<passed enum="">), value), how can I test to see if the passed value is actually a valid value within an enum?
|
|
|
|
|
|
Just out of curiosity, did you read the post? Did you feel it answered my question? I did not...
This blog posting predates the book I was referring to (Practical Guidelines and Best Practices (for MS VB and Visual C# Developers, Microsoft Press, 2005). It appears to merely restate the problem - do validate the arguments, don't use IsDefined . Although, it does add some reasons why IsDefined is bad...
What is the alternative, then?
|
|
|
|
|
About all you could do is test the contiguous ranges, so suppose you had the following defined:
public enum MyEnum
{
Enum1 = 0,
Enum2 = 1,
Enum3 = 3,
Enum4 = 10,
Enum5 = 20
} You could do this as
if (myValue >= (int)MyEnum.Enum1 && myValue <= (int)MyEnum.Enum3 || myValue == (int)MyEnum.Enum4 || myValue == (int)MyEnum.Enum5)
{
} It's not pretty but it would work.
|
|
|
|
|
Heh. My enum has 68 members. Basically, I'd have to loop through them all, checking equivalency. This was a solution I already passed on once...
Why oh why didn't they implement the InvalidEnumException, I will never know (yes, I know there's one in System.ComponentModel, but you can see right in the article that MS doesn't want you using that one, either).
Sigh. Write my own.
|
|
|
|
|
I am developing a program running on mobilephone using c# 2005,when my program is running,I need to know if the mobilephone is downloading or uploading data from internet online,how to do it?
|
|
|
|
|
Not sure. But I would try to watch packets and see if they are being transmitted or received.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
how to watch if the packets are being transmitted or received?
|
|
|
|
|
Through the networking classes already built into the framework.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Check whether or not the power is on?
|
|
|
|
|
I'm hoping someone can help on this one as it has been driving me mad for most of the day now...
In my application I have a panel with a number of dynamically generated controls (TextBoxes and RichTextBoxes, generated from xml) and I'd like to be able to drag these controls onto another panel. My question is rather simple (I hope) - is it possible to assign an event handler at runtime so I can perform the desired D&D and how would I go about it (any pointers would be most welcome )?
P.S. I've only been programming in C# for about 8 weeks (and liking it so far) so apologies if this is a stupid question...
|
|
|
|
|
Yes, it is possible to programatically assign event handlers to controls. I have whipped up a quick example below. Hopefully you'll be able to tweak the code below to suit your needs.
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
TextBox textBox = new TextBox();<br />
<br />
textBox.TextChanged += new EventHandler(this.TextBox_TextChanged);<br />
<br />
this.Controls.Add(textBox);<br />
}<br />
<br />
private void TextBox_TextChanged(object sender, EventArgs e)<br />
{<br />
}<br />
|
|
|
|
|
Jeez - simple when you know how! I can't believe I was toiling over it for that long! Thanks for your help J$ & SK Genius!
I can sleep at last!
Thanks again!
|
|
|
|
|
Hi, if you can do it with Visual Designer, then you can have a peek at the code it generates
and do something similar. There is no magic involved, the Designer just emits some code.
|
|
|
|
|
Event handlers are always asigned at runtime really...
You just have something like:
this.control.OnClick += new blahblahblah(someMethod);
Of course you will need to have already written the method you assign to the event. To get the exact code for an event and its method (as in what parameters you need, and what derivitive of EventArgs you need), add the desired event to any control, pop over to the designer generated code (probably in *filename*.designer.cs) and you will be able to see the code there, just Ctrl+F the name of the control you used.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
I'm writing a service that watches a folder for new files, and kicks off a thread to process the file. The problem is that two threads are being created at the same time (for the same file), and I have no idea why.
Here's the initialization for the watcher object:
string folderToWatch = "C:\\testfolder";
folderWatcher = new FileSystemWatcher(folderToWatch);
folderWatcher.BeginInit();
folderWatcher.EnableRaisingEvents = false;
folderWatcher.Filter = "*.xyz";
folderWatcher.IncludeSubdirectories = false;
folderWatcher.NotifyFilter = NotifyFilters.FileName;
folderWatcher.Created += new FileSystemEventHandler(folderWatcher_Created);
folderWatcher.EndInit();
The folderWatcher is started when the service is started.
Here's the handler for the Created event:
private class ThreadData
{
public string m_fileName;
public ErrorHandler m_errorHandler;
public int m_threadID;
}
private void folderWatcher_Created(object sender, FileSystemEventArgs e)
{
ThreadData data = new ThreadData();
data.m_fileName = e.FullPath;
data.m_errorHandler = this.m_errorHandler;
Thread thread = new Thread(new ParameterizedThreadStart(UploadFile));
thread.Name = JustFileName(e.FullPath);
data.m_threadID = thread.ManagedThreadId;
thread.Start(data);
}
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
You can't rely on only one create event per file created. This behavior is not deterministic between applications.
Notepad, for example, tests to see if a file exists by trying to create it first. Then it deletes it, and then it creates it. So you can get a bunch of the same FSW events for the creation of a single file.
By the way, I learned this by reading some article here on codeproject, as I recall . In the comments on the article, people were also talking about a horrible memory leak their FSW was causing, and nobody had a solution for that, either.
|
|
|
|
|
In fact, the Net is rife with examples of your same problem. Trying to find the article I saw before, I googled "FileSystemWatcher Notepad" and got many hits, talking about the multiple creation event problem. Here's an example:
http://community.bartdesmet.net/blogs/bart/archive/2004/10/21/447.aspx[^]
Note that a google of "FileSystemWatcher multiple creation events" would have turned up an even better review of articles on this.
Some of the articles/blogs/text linked claimed to have solutions, also.
|
|
|
|