|
Any help is greatly appreciated.
I've made a few changes.
<br />
[STAThread]<br />
static void Main()<br />
{<br />
Thread t = new Thread(new ThreadStart(WorkerThread));<br />
t.ApartmentState = ApartmentState.STA;<br />
t.Start();<br />
}<br />
<br />
static void WorkerThread()<br />
{<br />
ServiceBase.Run(new System.ServiceProcess.ServiceBase[] { new TestSvc() });<br />
}<br />
and in the onStart Method, when window services starts, it stills show
thread as MTA. I am just LOST... Unless, there is something I'm missing here.
Stanley
|
|
|
|
|
I am new to C# and I am having some problem understanding arrays. I am getting the following exception:
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
The problem seems to be (string)ie.Current. I do not understand why I cannot retrieve the value. Any ideas would be appreciated.
<br />
using System;<br />
using System.Collections;<br />
<br />
namespace ConsoleApplication2 <br />
{<br />
<br />
class Class1 <br />
{<br />
<br />
[STAThread]<br />
static void Main(string[] args) <br />
{<br />
Hashtable region = new Hashtable();<br />
IDictionaryEnumerator ide;
ArrayList al;<br />
IEnumerator ie;
string indicator = ""; <br />
<br />
do <br />
{<br />
Console.Write("Enter region name: "); <br />
region.Add(Console.ReadLine(), new ArrayList()); <br />
<br />
Console.Write("Enter another region? (y/n): ");<br />
indicator = Console.ReadLine();<br />
<br />
} while(indicator.ToUpper() == "Y");<br />
<br />
ide = region.GetEnumerator();<br />
while (ide.MoveNext()) <br />
{<br />
al = (ArrayList)ide.Value;<br />
al.Add("foo");<br />
}<br />
<br />
ide = region.GetEnumerator();<br />
while (ide.MoveNext()) <br />
{<br />
al = (ArrayList)ide.Value;<br />
ie = al.GetEnumerator();<br />
while (ie.MoveNext()) <br />
{<br />
Console.WriteLine("hash key: {1} array value: {2}",(string)ide.Key, (string)ie.Current);<br />
} <br />
<br />
Console.WriteLine(ide.Key);<br />
Console.WriteLine(ide.Current);<br />
}<br />
<br />
Console.ReadLine();<br />
}<br />
}<br />
<br />
<br />
}<br />
|
|
|
|
|
Have you made sure that ie.Current is a string ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Yes, actually I cast it just in case:
(string)ie.Current
|
|
|
|
|
I can see that you cast it, and I'm sure there is a magical world in which this will always work. Have you stepped through to make sure that it is a valid target for this cast, and checked what the value is when it fails ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
When I step into the program I see that ie.Current is equal to "foo" as expected. However, before it prints the line it throws an exception and highlights ie.MoveNext(). But, if I remover {2} from the string it operates as expected.
Like I said I'm new to C# so please bare with me as I may be missing something simple.
Thanks
|
|
|
|
|
Got it. The format string is zero indexed - you are asking for values 1 and 2, but the values you provide are numbers 0 and 1, hence the error on array indexing.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
This may be a stupid question but based on my code sample, how would I go about fixing the problem? I've been pulling my hair on this one for quite some time.
Thanks -- I owe you a beer for this one!
|
|
|
|
|
*grin* I remember when I was starting, asking questions that seemed impossible to me, and feeling dumb when I found out the answer. I recommend the book 'Inside C#' by Tom Archer. Make sure you get the second edition.
Replace the 1 with a 0, and the 2 with a 1. That way you're asking for the first two items specified, rather than the second and third ( currently non-existent ) item.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Oh my gosh -- I should have known that. I must have had one of those retarded moments.
Thank you once again!!!
|
|
|
|
|
Hello,
I want to use GPS in my Smart Device Application. Can anybody here give me any information about it? - It is difficult to implement? Is there any literature, code samples, etc. available?
thanks in advance.
regards
mat
|
|
|
|
|
Yes, and a search on google[^] would turn up lots of articles.
There's even several good ones here on CodeProject[^].
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi! I'm quite new to c#, and i am currently learning a lot about interfaces and c#. Seriously, i never asked before for a problem, but THIS one drives me crazy!
Ok, first i'm using .Net Frameworks 2.0 with VC# Express Beta, on a XPSP2 system. The problem started when i tried to add custom icons for my forms. Every icons that I've added are handled in a xml file called resources.resx. I've removed some icons from this file whithin the editor and any declarations related to them and since, i got this exception every times i start the program:
ArgumentException was unhandled
ResourceManager base name should not end in '.resources'. It should be similar to 'MyResources', which the ResourceManager can convert into <base />.<culture>.resources, for example, 'MyResources.en-US.resources'.
Thats it. I've searched for hours on this problem and i wasn't able to find something about. In english, what does this exception means? Does my ResourceManager try to call an inexistant object?
Thanks if you can help me!
|
|
|
|
|
First of all, keep in mind that "Whidbey" is still in beta. Second, there is no reason that the ResourceManager should ever look for MyResources.en-US.resources if "en-US" is your neutral language (i.e., the language in which your application was written). You use the NeutralResourcesLanguageAttribute to specify the neutral language - an assembly attribute (prefix with "assembly:") - which avoids 4 or more look-ups for satellite assemblies.
Even without that attribute, the neutral language is simply "MyResources.resources" (for example).
To learn more about resources and the ResourceManager , read Resources in Applications[^] in the .NET Framework SDK.
If you're specifying a resource, you do not include the ".resources". You would only specify "MyResources". The ResourceManager and its derivatives like ComponentResourceManager take care of getting an object for the thread's UI culture (Thread.CurrentUICulture ), or another CultureInfo that you could specify. If you specified MyResources.resources or MyResources.en-US.resources, then the ResourceManager wouldn't play much role.
You only specify a Type or resource name without any localization information in it (like MyResources). The topics I linked above will explain more.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
problem: i have a web browser embedded in my form. the pages i am creating visually complicated enough that i don't want to do it by hand, so i'm going to make the pages in front page. the issue is getting that front page generated html back to my C# web app as a properly formed string. instead of having to manually do things like replace all the "s with \"s, i'm trying to embed the html page as a resource, and extract it at run time. will this solve all my formatting issues? how do i extract it at runtime? if i add the html page to my project, change build action to "Embedded resource", i thought i coudl do a resources.GetObject and pass it the name of the file, but i keep getting back null.
and please let me know if you know a better way to get html generated code from front page into C# as a properly formatted string. thanks!
|
|
|
|
|
ResourceManager.GetObject would not work. A ResourceManager is created for a specific .resources embedded resource.
If you change a build action for a file to "Embedded Resource", you use Assembly.GetManifestResourceStream with the full resource name ("namespace" plus file name):
private void ExtractResource(string resource, string destination)
{
using (Stream s = this.GetType().Assembly.GetManifestResourceStream(resource))
{
using (FileStream file = new FileStream(destination, FileMode.Create))
{
int read = 0;
byte[] buffer = new byte[4096];
while ((read = s.Read(buffer, 0, buffer.Length)) > 0)
file.Write(buffer, 0, read);
}
}
} To use this, specify the name of the embedded resource (like "MyProject.MyFile.htm" - however the concatenation of the root namespace (configured in the Project Settings) + sub-folders + filename would look) and the destination path of the file.
For the destination, I would recommend using isolated storage which requires fewer code access security (CAS) permissions than even writing to the TEMP directory (via Path.GetTempFileName or something). See the IsolatedStorage class in the .NET Framework SDK for more information. You wouldn't have to use it, but it would make your application more robust if you planned on deploying it from different security zones (intranet or Iternet, as opposed to just running it from a local machine).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I made a Minesweeper.
But i have a problem...
Every square in the program is a UserControl, and i use Bitmap for the imagens, setting the Background...
In the Master Level ( 50x50 ) the program is extremlly heavy and laggy
What can i do?
Other methods to put the images?
Thanks.
|
|
|
|
|
Don't use a UserControl when a simple Control will do. UserControl s are containers and have a lot of overhead. Controls are simple objects - like a Button , which might be a better control to extend for your use - and would have less overhead.
But, realistically, don't use a control at all. Use a single control (perhaps even the Form itself) that manages the grid and draws the grid accordingly, as well as handling the painting operations by overriding OnPaint . This is a much more common approach and will have much less overhead than using either UserControl s or Control s.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello,
I am writing a C# windows application. I would like to open a command prompt and execute a few lines of code. I am able to open the command prompt using the following code:
System.Diagnostics.Process.Start("cmd.exe");
But I don't know how to actually write a command to the prompt once it is open. Can anyone help me out?
Thanks,
RC
|
|
|
|
|
If you read the documentation for the Process.Start method, the following should be evident:
Process.Start("cmd.exe", "/c someapp.exe"); Other documentation for members of the Process class show examples of how to capture console output.
Please note that if an application uses the console subsystem, you don't actually need to start cmd.exe (the command environment for Windows NT - command.com for Windows (9x/ME)). A console program in Windows NT (NT4, 2000, XP, and 2003, plus all future Windows platforms) will automatically start in a console window, which you can suppress by using the Process.Start(ProcessStartInfo) method override and set ProcessStartInfo.CreateNoWindow to true .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hello,
I developed a Web-Service which i want to consume from a Smart Device Application. I developed the Smart Device Application and create a Web Reference to the Web Service, but when i want to test the Smart Device Application in the Emulator the following error occurs:
A managed WebException occured at SoapHttpClientProtocol:doInvoke+0x23f
Unable to connect to the remote server
SoapHttpClientProtocol::doInvoke+0x23f
SoapHttpClientProtocol::Invoke+0x9
Service1::GetHypotenuse+0x17
Form1::ctor+0x3a
Form1::Main+0x5
Ok to terminate
Other Desktop WebClients which consumes WebServices on my Desktop works, and also a MobileWebApplication which consumes the same WEb-Service as the SmartDeviceApplication works, only when i want to test the Smart Device Application in the Emulator the error occurs.
Can anybody help me??
thx
regards
mat
|
|
|
|
|
Is your emulator correctly configured to connect to the Internet through ActiveSync or some COM port? If not, you won't be able to establish a connection. The fact that applications on your desktop machine can connect, and that a Mobile ASP.NET web application can connect to the web services - but your smart device can'ts - points toward your device not being properly connected.
For help with configuring your device or device emulator correctly, please visit the Embedded / Mobile[^] forum here on CodeProject. It would not be a C# issue.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I would also be sure that you the reference to your web service is not set to "localhost". I had similar problems until I discovered this small, but important, problem.
|
|
|
|
|
So i think the emulator is configured in a right way, because the emulator works with other Smart Device Application which do not consume Web-Services. So think it is nearly the problem chris mentioned with the Web-Reference. I still thought that it might be something like this, but i deleted the Web-Reference and created a new one, but still the same problem..?? Do you know any further idea?
regards
mat
PS: i created the Web-Reference as usual. I go to the Reference Directory in the Smart Device Application solution, go to Add Web Reference and then search on the local base for my Web-Service and then click on Add Reference.
|
|
|
|
|
Just because one smart device application is working doesn't mean another would. The difference is that your web service consumer requires a network connection. Another smart device application may not (like a calculator or game or something).
If you search on your local host, the web reference that gets created would reference "localhost", which is always 127.0.0.1, or the local machine. You need to address your machine with the web service using a remote IP or name that resolves to something other than 127.0.0.1 like "localhost" would.
To determine if your emulator is not connected correctly, start pIE (Pocket Internet Explorer) and see if you can browse to an external site (either on your intranet or the Internet - not just a page loaded from the device like the default home page). If you cannot resolve a remote host then post a question aobut configuring the emulator to the mobile forum I posted a link to before.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|