|
Look here[^]. zead wrote:
I was developed a c# windows application and now I want to create a setup package for it that contains the SQL SERVER and .NetFramework and the application itself. I don't think you can package SQL server with your application. Not sure if the license allows to do this.
|
|
|
|
|
I wrote one .net c++ dll,and reference it in an c# winform program .Prompt the following error:
title: BadImageFormatException was unhandled
content:
Could not load file or assembly “CppDll, Version=1.0.4798.31848, Culture=neutral, PublicKeyToken=null”or one of its dependencies.
the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well.
This is a very simple test example code:
part dll code:
namespace CppDll {
public ref class Class1
{
};
}
part exe code:
public Form1()
{
CppDll.Class1 cls = new CppDll.Class1();
InitializeComponent();
}
|
|
|
|
|
peter462 wrote:
the Default cpu settings is anycpu,when i change it to x64,the result is the same.but when i change it to x86 it can work well. Where are you changing? In the C# project?
|
|
|
|
|
It doesn't work because you compiled your C++ .DLL as 32-bit. You cannot mix 32- and 64-bit code in the same process.
Either recompile your .DLL as 64-bit or go into your C# project properties and target x86 (32-bit) to force your C# code to run as 32-bit only.
|
|
|
|
|
This is why the default setting isn't Any CPU anymore.
|
|
|
|
|
Hello friend!!
I will required the whole static text present on external application's input box or message box.
For example consider Microsoft word as external application which is password protected.
Suppose my file name is "Demo.docx", when I clicked on this file the "password" input box is opened as i have already mentioned my file is password protected.
The "Password" input box will contain static information message as follows:
Enter the password to open file "C:\...\sham\desktop\Demo.docx"
So my requirement is to getting this static message present on external application's input box or message box.
Is there any way to read out this message programmatically??
|
|
|
|
|
sham bhand wrote:
Is there any way to read out this message programmatically?? I don't think there is way to do this completly using .NET classes. You have to work with native windows functions to do this. The idea is
1 - Get the window handle for the textbox you need to read. You can use FindWindow()[^] or FindWindowEx[^] to get a window handle.
2 - use SendMessage and send WM_GETTEXT to the handle to get the text.
|
|
|
|
|
Check out the "UI Automation" classes in the .NET framework.
Google "UI Automation C#" to get started.
|
|
|
|
|
Actually I am Beginner To C# and i don't know how to do it can you give me one sample code about this.
|
|
|
|
|
|
Hello. I am trying to get CPU usage using the PerformaceCounter class. I am using the following code which I see everywhere on online tutorials. Still it does not produces the expected result.
PerformanceCounter pc = new PerformanceCounter();
pc.CategoryName = "Processor";
pc.CounterName = "% Processor Time";
pc.InstanceName = "_Total";
long lResult = (long)pc.NextValue();
Now lResult always returns ZERO. Why is it so?
Related Question: I have managed to get the list of CounterName (s) but how do I get the list of InstanceName (s)? (i.e. _Total )
Thanks for any input.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
I working with C# 2008 and 2012 windows applications that need to call different executables.
Are there other ways to call theses processes besides the way I have the code listed below:
Process eProcess1 = new Process();
eProcess1.StartInfo.FileName = strConsoleAppLocation;
Process1_Arguments = " 10 " + kgID;
eRPT_Process1.StartInfo.Arguments = Process1_Arguments;
eRPT_Process1.Start();
If there are other ways to start a process, can you write the code and/or point me to a reference that
will display other ways that an executable can be run from C# code?
|
|
|
|
|
You could manually invoke ShellExecuteEx , but that'd be more complicated without giving much advantages (if any).
I'm curious, why are you looking for an alternative?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
This application just went into production. I am tryuing to determine if 'extra' processes can be started with other kinds of C# statements in the code.
|
|
|
|
|
classy_dog wrote: I am tryuing to determine if 'extra' processes can be started with other kinds of C# statements in the code.
Search your code for the Proces class.
If there's a static class somewhere, loaded once every full moon, with some "unmanaged resources", you might have the same problem. Another way of executing code would be by compiling it on the fly, and to generate the required call to the Proces-class on demand, from an encrypted string.
Still curious what you're looking for, might help in giving a more useful answer.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I am getting the following error message on the production server:
Process 9528 (\Device\HarddiskVolume2\Program Files (x86)\red\sampleclient.exe) has opened key \REGISTRY\USER\S-1-5-21-11-222-333\Software\Microsoft\SystemCertificates\TrustedP eople
Process 8880 (\Device\HarddiskVolume2\Program Files (x86)\red\sampleclient.exe) has opened key \REGISTRY\USER\S-1-5-21-11-222-333\Software\Microsoft\SystemCertificates\TrustedP eople
Process 9528 (\Device\HarddiskVolume2\Program Files (x86)\red\sampleclient.exe) has opened key \REGISTRY\USER\S-1-5-21-11-222-333\Software\Microsoft\SystemCertificates\My
Process 8880 (\Device\HarddiskVolume2\Program Files (x86)\red\sampleclient.exe) has opened key \REGISTRY\USER\S-1-5-21-11-222-333\Software\Microsoft\SystemCertificates\My
Process 9528 (\Device\HarddiskVolume2\Program Files (x86)\red\sampleclient.exe) has opened key \REGISTRY\USER\S-1-5-21-11-222-333\Software\Microsoft\SystemCertificates\Disallow ed
Process 8880 (\Device\HarddiskVolume2\Program Files (x86)\red\sampleclient.exe) has opened key \REGISTRY\USER\S-1-5-21-11-222-333\Software\Microsoft\SystemCertificates\Disallow ed
This keeps processes running on the production server. The production server does not release reources.
I am tyring to figure out what could be causing this problem.
This application connects to a web service. The code I am using was initially obtainexd from the company that werote the web service.
There are *.xsd files in a proxy attached to this code I am running.
Thus do you think I need to contact the company with the web service to see what has changed on their side?
|
|
|
|
|
classy_dog wrote: The production server does not release reources.
How does that relate to the messages you posted? And how are you measuring those?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
This is the error message that is occuring in production. At the same time the processes in memory created by the program called main are not released. This look like what is causing out server memory to become full.
Do you ave any other ideas?
|
|
|
|
|
classy_dog wrote: This is the error message that is occuring in production.
It doesn't look like an exception; there is no stack-trace. They don't even look like errors, but like an audit; only two o' them failed.
classy_dog wrote: At the same time the processes in memory created by the program called main are not released.
Even if those events are correlated, unless you can track it to your code - all you can do is complain about "Windows", with the error probably being in some 3rd party-unmanaged piece o' code.
How are you determining that the memory isn't released? Don't say "task-manager", say "memory profiler".
classy_dog wrote: This look like what is causing out server memory to become full.
You might be hunting a false track; if you suspect your app has a memory-leak, then start tracking memory-allocation.
I'm getting the feeling that I've read these answers that I'm writing just a few days ago. Did we have this discussion before?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Some argue Thread.Sleep is evil - [^]
Thread.Sleep is one-line of code, simple, and get the job done. I must say I disagree with the author of this ... discussion referenced.
SCENARIO 1 - wait for async task completion: I agree that WaitHandle/Auto|ManualResetEvent should be used in scenario where a thread is waiting for task on another thread to complete.
SCENARIO 2 - humble timing while loop: However, as a crude timing mechanism (while+Thread.Sleep) is perfectly fine for 99% of applications which does NOT require knowing exactly when the blocked Thread should "wake up*. The argument that it takes 200k cycles to create the thread is also invalid - the timing loop thread needs be created anyway and 200k cycles is just another big number (tell me how many cycles to open a file/socket/db calls?).
So if while+Thread.Sleep works, why complicate things?
dev
|
|
|
|
|
devvvy wrote: Thread.Sleep is one-line of code, simple, and get the job done
Just because it's simple to implement, this doesn't mean it's a good choice. I recommend against Thread.Sleep precisely because of what it does - it suspends a thread for a timeout period. That doesn't seem too bad if you want to wait for a period, but the big problem comes when you want to terminate that thread. When a thread is sleeping, terminating it isn't easy - effectively, you have to wait for the thread to wake up just to kill it. This may not seem to be too big a deal, but if your system relies on having a number of these internally, you have just forced the user to wait and that's generally not a good thing.
The primary reason that I recommend against it is precisely because it's so easy to use. The problem is, people end up using it as a blunt object and force it into programs that it shouldn't be in, precisely because they don't understand the downsides. If you fully appreciate the tradeoffs in Thread.Sleep then, by all means, use it. Don't, however, put it into code that a noob is going to read - as they probably don't appreciate the underlying issues with Thread.Sleep then they will blindly use it.
There are other, subtle, problems with the use of Thread.Sleep, with relation to priority. A simple pattern, though, is simply to use Monitor.Enter to control the access, and this is my preferred choice in a lot of cases.
|
|
|
|
|
SCENARIO 1 - wait for task completion on another thread: I agree as I stated earlier not to use Thread.Sleep and that it's just outright wrong to do so.
SCENARIO 2 - humble timing while loop: I'm not hearing any reason not to use it. As indicated
* just because it's simple doesn't mean it's inappropriate
* the thread which host the while loop needs be created anyway so thread creation cost is irrelevant
* most applications don't need to know when *exactly* the blocked thread needs to *wake* up after specified period
* alternative is to use a timer+event/subscriber which does nothing more than complicate an otherwise cannot-be-simpler while loop with a Thread.Sleep
SCENARIO 3 Thread.Sleep(MagicDuration) or app breaks - well... this is a bug which demands correction in the first place.
I'm not hearing any new argument in support of not using Thread.Sleep in SCENARIO 2 -
- SCENARIO 1/3 is just plain stupid for anyone to use Thread.Sleep
- SCENARIO 2 not using simple Thread.Sleep is just waste of *my* time
This is an over discussed subject, gives people wrong impression this is actually complicated, that Thread.Sleep is really evil.
dev
|
|
|
|
|
Thread.Sleep() is not EVIL if you know how it works and if that's the behavior that you really want to accomplish. The reason people say it is evil because they use it wrongly without understanding how it works. devvvy wrote:
SCENARIO 2 - humble timing while loop: I'm not hearing any reason not to use it. As indicated If your application doesn't care about accuracy of the execution ineterval, then Thread.Sleep() is alright to use. Let us say you need to execute some task every minute and you start the application at 10AM. It is supposed to execute at 10.01, 10.02, 10.03 etc. You'd write something like,
while(!exit)
{
Thread.Sleep(10000);
} What happens if your job takes more than 1 minute? Then the next run which was supposed to happen at 10.01 won't happen. This delays the next execution too. With this design, it will be hard to tell when the next run will happen. If this behavior is alright for your application, there is no problem in using Thread.Sleep() . To workaround this problem, you can use System.Threading.Timer to schedule the job. It gives a better scheduling capabilities and executes the job exactly at the interval that you specify. Timer callback method can be executed simultaneously by multiple threads if the job takes more time than the interval. This increases parallelism and makes the processing faster.
It is also logical to think that why do you need to waste a thread by just sleeping? The wastage could be minimal, but it is a wastage. Where System.Threading.Timer uses thread pool threads and thread pools are more optimized for better usage of resources. Thread pools are initialized with a set of threads when the application domain starts. devvvy wrote:
This is an over discussed subject, gives people wrong impression this is actually complicated, that Thread.Sleep is really evil. It's about maturity. If you know how Thread.Sleep() works then you'd probably use it correctly and use alternatives where Thread.Sleep() is not the right solution. Any statement which says Thread.Sleep() is evil without understanding the context where it is used is STUPID.
Best wishes,
Navaneeth
modified 18-Feb-13 23:36pm.
|
|
|
|
|
To overthrow the uneducated accusation on Thread.Sleep from self righteous syntax high priests
(but i pointed out very beginning timer/handler as alternative + exactly when next loop gets executed is un-important for 99% of the apps)
dev
|
|
|
|
|
In scenario 2, you're confusing the need to create the thread with the need to use it as a timer. If you need to use something as a timer, then why not use a timer? However, this case is the one that is potentially the most dangerous. Suppose that your application creates 10 threads and then puts them to sleep for 30 seconds, and each thread has opened up some resources that must be disposed of when the thread completes. Now, suppose that 2 seconds into this, your application wants to close - what do you think the effect will be?
The reason that it's so discussed is that it does have drawbacks, and it can be inherently risky. It's very simplicity is what makes it so attractive, and it can end up being used when it is inappropriate to do so because you don't appreciate the subtleties involved in using it. Threading and multi-tasking is not an easy thing to get right, it really isn't. As I said earlier, using it when you know exactly what goes on with it is fine, it's when you don't understand the drawbacks that it's a problem. And using something because it's slightly less typing than the alternatives is just lazy programming - don't use something because it saves you a few keystrokes, use the tool that is right and appropriate.
|
|
|
|