This is a discussion on Windows Forms Application Interview Tips and Tricks within the Interview Questions & Answers and Tips forums, part of the DiscussWeb IT Curriculum category; Hi Techies, Let's start posting general Windows Forms Application interview questions and answers in this thread. Thanks...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
#1
| |||
| |||
| Hi Techies, Let's start posting general Windows Forms Application interview questions and answers in this thread. Thanks |
|
#2
| |||
| |||
| How can I run an EXE from within my application? Use the Process class found in the System.Diagnostics namespace. [C#] Process proc = new Process(); proc.StartInfo.FileName = @"Notepad.exe"; proc.StartInfo.Arguments = ""; proc.Start(); [VB.NET] Dim proc As New Process() proc.StartInfo.FileName = "Notepad.exe" proc.StartInfo.Arguments = "" proc.Start() |
|
#3
| |||
| |||
| What are the common issues in redirecting assemblies using the publisher policy files? 1) Make sure to follow proper naming conventions for the policy dll. For example, if the original assembly name is TestAssembly.dll then the corresponding policy assembly should be called "policy.1.0.TestAssembly.dll" to make this redirection work for all "1.0.*" version bindings of the original assembly. 2) While specifying the name for the assembly in the policy file, do not include the ".dll" extension. This is wrong: >assemblyIdentity name="TestAssembly.dll" publicKeyToken="f638d0a8d5996dd4" culture="neutral" /< Instead use: >assemblyIdentity name="TestAssembly" publicKeyToken="f638d0a8d5996dd4" culture="neutral" /< 3) Make sure to sign the policy assembly with the same strong name as the original. 4) Make sure to distribute the policy file along with the policy assembly. Installing the policy assembly in the GAC alone will not suffice. Note that any change made to the policy file after creating the policy assembly will not take effect. 5) Always use /link (to the policy file) in the "al" command while creating the policy assembly. Do not use /embed. It doesn't seem to be supported. Some good links: Welcome to the MSDN Library http://www.newtelligence.com/downloa...basta2001.aspx Only For Gurus |
|
#4
| |||
| |||
| How can I find all programs with a GUI (not just arbitrary windows) that are running on my local machine? You could use EnumWindows with p/Invoke, but using the static Process.GetProcesses() found in the System.Diagnostics namespace will avoid the interop overhead. [C#] Using System.Diagnostics; ... foreach ( Process p in Process.GetProcesses(System.Environment.MachineNam e) ) { if( p.MainWindowHandle != IntPtr.Zero) { //this is a GUI app Console.WriteLine( p ); // string s = p.ToString(); } } [VB.NET] Imports System.Diagnostics ... Dim p As Process For Each p In Process.GetProcesses(System.Environment.MachineNam e) If p.MainWindowHandle <> IntPtr.Zero Then 'this is a GUI app Console.WriteLine(p) ' string s = p.ToString(); End If Next p There is one potential problem on Windows 98. If a process was started with ProcessStartInfo.UseShellExecute set to true, this MainWindowHandle is not available. |
|
#5
| |||
| |||
| How can I get a list of all processes running on my system? Use the static Process.GetProcesses() found in the System.Diagnostics namespace. [C#] Using System.Diagnostics; ... foreach ( Process p in Process.GetProcesses() ) Console.WriteLine( p ); // string s = p.ToString(); [VB.NET] Imports System.Diagnostics ... Dim p As Process For Each p In Process.GetProcesses() Console.WriteLine(p) ' string s = p.ToString() Next p |
|
#6
| |||
| |||
| How can I make sure there is only one instance of my application running? Saar Carmi shows how to do this in his sample found on C# Corner. In it, he uses the Process class in System.Diagnostics to implement this functionality using code such as [C#] public static Process RunningInstance() { Process current = Process.GetCurrentProcess(); Process[] processes = Process.GetProcessesByName (current.ProcessName); //Loop through the running processes in with the same name foreach (Process process in processes) { //Ignore the current process if (process.Id != current.Id) { //Make sure that the process is running from the exe file. if (Assembly.GetExecutingAssembly().Location.Replace( "/", "\\") == current.MainModule.FileName) { //Return the other process instance. return process; } } } //No other instance was found, return null. return null; } [VB.NET] Public Shared Function RunningInstance() As Process Dim current As Process = Process.GetCurrentProcess() Dim processes As Process() = Process.GetProcessesByName(current.ProcessName) 'Loop through the running processes in with the same name Dim process As Process For Each process In processes 'Ignore the current process If process.Id <> current.Id Then 'Make sure that the process is running from the exe file. If [Assembly].GetExecutingAssembly().Location.Replace("/", "\") = current.MainModule.FileName Then 'Return the other process instance. Return process End If End If Next process 'No other instance was found, return null. Return Nothing End Function 'RunningInstance |
|
#7
| |||
| |||
| How do I determine which operating system is running? The Environment class in the System namespace has this information. [C#] string versionText = Environment.OSVersion.Version.ToString(); [VB.NET] Dim versionText As String = Environment.OSVersion.Version.ToString() The Version property has member properties such as Major and Minor that give additional information. Note that XP is windows version 5.1 |
|
#8
| |||
| |||
| How can I get all IP addresses for my local machine? [C#] string s =""; System.Net.IPAddress[] addressList = Dns.GetHostByName(Dns.GetHostName()).AddressList; for (int i = 0; i < addressList.Length; i ++) { s += addressList[i].ToString() + "\n"; } textBox1.Text = s; [VB.NET] Dim s As String = "" Dim addressList As System.Net.IPAddress() = Dns.GetHostByName(Dns.GetHostName()).AddressList Dim i As Integer For i = 0 To addressList.Length - 1 s += addressList(i).ToString() + ControlChars.Lf Next i textBox1.Text = s |
|
#9
| |||
| |||
| My user does not have .NET installed. Will he be able to run my Windows Forms application? No, the .NET runtime platform has to be on any machine that will run your Windows Forms application. Microsoft has made the .NET runtime platform installation (dotnetredist.exe) available as a free download from Microsoft .NET Framework Redistributable . |
|
#10
| |||
| |||
| How do I get the path to my running EXE? The Application class has a static member ExecutablePath that has this information. [C#] textBox1.Text = Application.ExecutablePath; [VB.NET] TextBox1.Text = Application.ExecutablePath |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Windows Tips & Tricks | vadivelanvaidyanathan | Operating Systems | 515 | 09-07-2009 08:15 PM |
| Windows Vista Tips & Tricks | prasannavigneshr | Operating Systems | 332 | 07-20-2009 08:24 PM |
| ASP.NET 2.0 Interview Tips and Tricks | santhakumar | Interview Questions & Answers and Tips | 339 | 03-20-2008 05:09 AM |
| ASP.NET 3.5 Interview Tips and Tricks | santhakumar | ASP and ASP.NET Programming | 21 | 03-14-2008 10:33 PM |
| Interview Tips & Tricks | venkatesan.N | Interview Questions & Answers and Tips | 2 | 08-28-2007 03:37 AM |
Our Partners |