N a v a n e e t h
Posts
-
Controling Video files -
Thread.Sleep is NOT evildevvvy wrote:
THUS FAR there isn't ONE SINGLE argument that justify against use of Thread.Sleep against SCENARIO 2.
As Pete already told, you are ignoring the comments that we made for Scenario2. See my answer.
Best wishes, Navaneeth My blog
-
Thread.Sleep is NOT evilPete O'Hanlon wrote:
Errm. Yes, we have posted arguments against, you're just choosing to ignore them.
I second that. He don't have the maturity to understand what people are saying. So no point in discussing further. :)
Best wishes, Navaneeth My blog
-
Setup Package for C# Windows applicationzead 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.
Best wishes, Navaneeth My blog
-
CLOSING FORMSProcess won't quit till the main form and all foreground threads finishes executing. If you close the Form1, it should get closed properly. Is that happening?
Best wishes, Navaneeth My blog
-
c# 64 bit .net c++ dll reference problempeter462 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?
Best wishes, Navaneeth My blog
-
How to read out whole static text present on external application's Input boxes or message boxes in C#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 sendWM_GETTEXT
to the handle to get the text.Best wishes, Navaneeth My blog
-
Thread.Sleep is NOT evilSimon_Whale wrote:
What would you recommend as a better method of doing the same as
thread.sleep
inside a thread?If you want to run a job which executes in every 'n' minutes, you can use
System.Threading.Timer
. If you want to wait till another thread finishes execution, you can use WaitHandle. If you just want to sleep, useThread.Sleep()
:)Best wishes, Navaneeth
-
Thread.Sleep is NOT evilThread.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)
{
// Do your job
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 useSystem.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. WhereSystem.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 whereThread.Sleep()
is not the right solution. Any statement which saysThread.Sleep()
is evil without understanding the context where it is used is STUPID.Best wishes, Navaneeth
-
web service keep a process openWhat process is active?
Best wishes, Navaneeth
-
harvesting social images for bi concept image search -
WebMatrix-FollowingBram van Kampen wrote:
The C# system I'm faced with, generates dozens of files, and lengthy tutorials. Unlike MFC, it does not appear to have a meaningful Help System. If I double Click a 'System' class name and press F1, I get a list of Tutorials(if anything at all) instead of a Help file which explains the class, and what methods are available.
System
is not a class but anamespace
. I never used to look for local help instead always check in online MSDN. They are pretty good and well documented. Try this[^]Bram van Kampen wrote:
There is no short explanation anywhere I can find,about which file does what, or how it glues together. It is to me totally unclear whether to start a Website or a Project. Does a Project contain many Websites, or does a Website contain many projects. What is the format of the End Product. An .exe or .dll file,as in MFC, a .cgi File, or what else.
A project can contain several C# files which will be compiled together. Output of the compilation depends on the type of project created. If the type is a class library, you get a DLL and an executable file when the project type is Console or Windows or WPF application. Usually, you will start with creating an empty solution. Then add projects into the solution. So all the componenets in your project can be separate Visual studio projects contained in a single solution file (.sln). Now you can specify the project dependencies and how they reference each other. Let us assume that you are building a website. You will create an empty solution, add a class library to it which contains your websites core logic which don't have any dependencies with web related components. This project could contain wrapper classes to your C++ library. Then you can add a ASP.NET project to the solutuion wich references the assembly from the class library project.
Bram van Kampen wrote:
I fully understand Machine code and assembler code. I am fully aware how the CPP Compiler and Linker work, and how the lot comes together at run time. MFC has Header Filesand Libraries, and pragma's to include a DLL. It istotally unclear to me what happensin C#,
In C# it is simple. No header files. Just a bunch of file
-
calling a method in c++ from c# -
Parsing a web page to get just the <p> inner text.What you have done is BAD. Ideal way to handle this is to use a HTML parser and traverse the DOM to get the text that you need. Look at HTML Agility[^] project. If you are sure that you will always have a wellformed input, you could easily do this with regular expressions. Here is a working example.
public static List<string> GetAllParagraphValues(string input)
{
List<string> values = new List<string>();
Regex r = new Regex("<p[^>]*>(?<value>.*?)</p>", RegexOptions.IgnoreCase);
foreach (Match match in r.Matches(input))
{
values.Add(match.Groups["value"].Value);
}
return values;
}Best wishes, Navaneeth
-
WebMatrixNo. Probably it should go to Web development discussions.
Best wishes, Navaneeth
-
WebMatrix-FollowingI don't see a good reason to use WebMatrix here. You should probably stick to ASP.NET alone.
Bram van Kampen wrote:
In MFC I stored all this in a C Structure (packed to byte alignment). Do the C# and C++ structures align. Do allignment pragma's exist in C#, How does C# allign DWORDS.(Big End, Little End, or Machine Dependent)
In C#, you can add a
StructLayout
attribute and with a kindExplicit
to the structure. Something like,[StructLayout(LayoutKind.Explicit)]
public struct Example
{
[FieldOffset(0)]
public int foo;
[FieldOffset(4)]
public int bar;
}This allows you to take finer control over alignment. If you write a wrapper to your native code in C++/CLI, you don't have to worry about structure alignment in C#. Just work with managed objects.
Best wishes, Navaneeth
-
calling a method in c++ from c#bonosa wrote:
the compiler doesn't like (void*)&ret_vals....
Add a method to
HdfCallVars
so that it can give you the underlying native struct.Best wishes, Navaneeth
-
Web development using C++ -
calling a method in c++ from c#bonosa wrote:
But do I need to make Channel Vars a wrapper class also?
If that is something which user has to create, you need to make it a managed class. All your internal structures don't need to be wrapped because you handle the creation of those inside your main managed object.
Best wishes, Navaneeth
-
forcing users to use English languageThis would be tricky. If you just want to ensure script used is English, it is easy. Just scan every character in the input and make sure all the characters are valid English letters. But user can write another language using the English script. Detecting this would be tough and you need to use some natural language processing libraries.
Best wishes, Navaneeth