Ask Questions & Get Answers at ibibo sawaal

113

Rank

8147

1692

26

34

How start another program from .NET? ?

Asked by Lucky Singh in Computers & Technology at   8:37 AM on December 03, 2008

Sudipta Deb's Answer

In order to initiate a new process using the .NET Framework, use the Process.Start method. More complex start-up parameters can be specified using the ProcessStartInfo class. This class allows output redirection, specification of command line parameters, etc.
Both the Process and ProcessStartInfo classes reside in the System.Diagnostics namespace.

Answered at 9:19 AM on December 03, 2008

Read all answers

How ensure that only one instance of an application will run? ?

Asked by Lucky Singh in Computers & Technology at   8:38 AM on December 03, 2008

Sudipta Deb's Answer

Often, it is necessary to be sure that only a single instance of an application will be running at a time. Examples include applications which control resources. There is a design pattern designed specifically for this purpose called the Singleton design pattern.
Another way of accomplishing this is by using a named mutex. The following example illustrates the creation of a mutex:
bool instantiated;

Mutex mutex = new Mutex
(false, "Local\\" + aUniqueID, out instantiated);

// If instantiated is true, this is the first instance
// of the application; else, another instance is running.
The mutex must be local—meaning it exists in the current user session. If the mutex were not local, users could share the mutex. Thus, two different users could not be running the program at the same time. Unlike various examples to be found on the Web, this sample code does not contain a call to a ReleaseMutex method. Because, the mutex will be released automatically when the process dies. If this is not the desired behavior, add such a method.
The mutex will not be garbage collected. Therefore, if a local variable is only used near the beginning of a method, the Garbage Collector (GC) may ignore it when determining which variables are garbage collection "roots" if that part of the method has already been executed. This can result in the mutex being released earlier than expected. To prevent premature release, make a call to:
GC.KeepAlive (mutex);
at the end of the Main method.
Or, use a static variable to hold the mutex. That ensures that the mutex will not be garbage collected until the AppDomain is unloaded. With this strategy, even should the Main terminate, there will not be any problems if other threads are running.
Another strategy is to "listen" on a local port. Since only one process can listen to a particular port, this fact can be exploited to ensure that only one instance of your application is running. But, there will be problems if another application tries to use that port for any purpose. Also, this strategy provides a communication channel between the initial instance and the new instance. For example, the new instance might want to tell the initial instance to open a user-requested file. This could be accomplished using the socket.

Answered at 9:18 AM on December 03, 2008

Read all answers

How get assembly attributes at runtime? ?

Asked by Lucky Singh in Computers & Technology at   8:38 AM on December 03, 2008

Sudipta Deb's Answer

The majority of assembly-wide attributes—usually specified in AssemblyInfo.cs—can be retrieved using Assembly.GetCustomAttributes. For example, code such as the following can be used to get the assembly title:
Assembly thisAssembly = this.GetType().Assembly;
obje ct[] attributes = thisAssembly.GetCustomAttribut es
(typeof(AssemblyTitleAttribute ), false));
if (attributes.Length == 1)
{
Console.WriteLine (((AssemblyTitleAttribute) attributes[0]).Title);
}
Not ice that AssemblyVersionAttribute becomes a part of the assembly name, which can be accessed via the Assembly.GetName method. The version can be accessed via the name with the Version property. For example:
Assembly thisAssembly = this.GetType().Assembly;
Cons ole.WriteLine (thisAssembly.GetName().Versio n);

Answered at 9:17 AM on December 03, 2008

Read all answers

How to read files with accented characters? ?

Asked by Lucky Singh in Computers & Technology at   8:38 AM on December 03, 2008

Sudipta Deb's Answer

Actually, this can be a large, complex topic. However, textual information—e.g. as stored in a file or sent over a network—is encoded; that is, the characters are converted into bytes according to some scheme. Therefore, bytes must be decoded to retrieve the information as characters again.
Normally, the encoding and decoding schemes must match or errors may result. And, this is the typical cause of decoding failures in which "extended" characters appear improperly decoded. (They may appear as empty boxes or as other incorrect characters.)

Answered at 9:18 AM on December 03, 2008

Read all answers

Should calling Initialize() on a reference type array fill it with objects? ?

Asked by Lucky Singh in Computers & Technology at   8:41 AM on December 03, 2008

Sudipta Deb's Answer

The Initialize() method of a System.Array class instance is designed to initialize value type arrays to their default values. But, it does not work on reference type arrays.
Actually, Initialize() is not designed for C# value type structs; because, C# structs cannot have default constructors which Initialize could call. Common Language Runtime (CLR) value types may have parameterless constructors; but in C#, there is no practical method of creating such a type.

Source: http://en.csharp-online.net/CS harp_FAQ:_Should_calling_Initi alize_on_a_reference_type_arra y_fill_it_with_objects

Answered at 9:12 AM on December 03, 2008

Read all answers

I want to know how to send a friend requiest in ibibo by person name as like orkut?

Asked by RAJ in Computers & Technology at   8:38 AM on December 03, 2008

Sudipta Deb's Answer

If you want to send a friend request in ibibo by person, then you need to go to that person's profile and then you will find a button to send friend request. In this way, you can send a friend request in ibibo by person name as like orkut.

Answered at 9:15 AM on December 03, 2008

Read all answers

Why does .NET make arithmetic errors? ?

Asked by Lucky Singh in Computers & Technology at   8:41 AM on December 03, 2008

Sudipta Deb's Answer

If you are new to computer arithmetic, you may have a few surprises coming. Computer arithmetic is necessarily done in binary (base 2); so, many floating point numbers can only be approximated in the binary. All runtime systems face these limitations, not just the .NET Common Language Runtime (CLR).
The following is a simple example:
double d = 0.1;
The value 0.1 must be stored in a variable of type double. But, that decimal value has no precise equivalent in binary. So, a value is stored which is as close to 0.1 as can be represented in a (binary) double type; but, the value is not exactly 0.1.
This potential problem exists for both double and float types where decimal fractions must be represented in binary.

Source: http://en.csharp-online.net/CS harp_FAQ:_Why_does_.NET_make_a rithmetic_errors

Answered at 9:10 AM on December 03, 2008

Read all answers

How can I port synchronized functions from Visual J++ to C#?

Asked by Lucky Singh in Computers & Technology at   8:46 AM on December 03, 2008

Sudipta Deb's Answer

Here is a Visual J++ source code example of a synchronized method:
public synchronized void Run()
{
// method body
}
The following is a port of the Visual J++ synchronized method to C# source code:
class Test
{
public void Run()
{
lock (this)
{
// method body
}
}

public static void Main() {}

}

Source: http://en.csharp-online.net/CS harp_FAQ:_How_can_I_port_synch ronized_functions_from_Visual_ Jplusplus%3F

Answered at 9:08 AM on December 03, 2008

Read all answers

What is the C# equivalent of the J++ instanceof operator?

Asked by Lucky Singh in Computers & Technology at   8:47 AM on December 03, 2008

Sudipta Deb's Answer

In C#, use the is operator, for example:
using System;

class ClassA {}

public class TestIs
{
public static void Test (object o)
{
ClassA a = null;

if (o is ClassA)
{
Console.WriteLine ("o is ClassA");
a = (ClassA) o;
}
else
{
Console.WriteLine ("o is not ClassA.");
}
}

public static void Main()
{
ClassA cA = new Class1();
Test (cA);
Test ("example string");
}
}

Source: http://en.csharp-online.net/CS harp_FAQ:_What_is_the_CSharp_e quivalent_of_the_Jplusplus_ins tanceof_operator%3F

Answered at 9:09 AM on December 03, 2008

Read all answers

How display int as a binary number, a string of 0s and 1s?

Asked by Lucky Singh in Computers & Technology at   8:41 AM on December 03, 2008

Sudipta Deb's Answer

The Convert class has an overload of the static ToString() method which accepts two ints and returns a string containing the specified number in the specified base.
For example, the following source code:
Console.WriteLine (Convert.ToString (128, 2) );

Source: http://en.csharp-online.net/CS harp_FAQ:_How_display_int_as_a _binary_number,_a_string_of_0s _and_1s

Answered at 9:11 AM on December 03, 2008

Read all answers

Editor's Pick

Categories

sawaal signature
sawaal free visiting card