Your best source of information and news about winvista, BIOS and windows vista on the internet

Vista ARTICLES TOP 50 Spyware Virus Vista SOFT Vista HELP

c#

You are currently browsing the articles from MS Windows Vista Compatible Software matching the category c#.

Clipboard Chaos!

Note: this content originally from http://mygreenpaste.blogspot.com. If you are reading it from some other site, please take the time to visit My Green Paste, Inc. Thank you.

OK, so perhaps chaos is a bit of a harsh word here. But the clipboard was recently driving me nuts! All I was trying to do was copy some text to it, and the operation was failing. Of course, as it was an ad hoc app, I didn't have any kind of error handling. The app worked just fine on one system, but running the app on another system (a virtual machine) consistently resulted in failure to copy the text to the clipboard.

Ultimately, I was able to determine what process was preventing my app from putting data in the clipboard, but I haven't yet found a decent workaround for when the problem happens. It's not critical for me, as the act of copying the text to the clipboard is more of a nicety than a requirement.

Anyway, using P/Invoke and System.Diagnostics, I found that vmusrvc.exe - the Virtual PC "Virtual Machine User Services" - had the clipboard open. Using the timestamps from Process Monitor's Profiling Events (generated at 100 ms intervals), and the timestamp of the failed operation from my app, I was able to determine the stack of vmusrvc.exe:

ntdll.dllKiFastSystemCallRet
vmusrvc.exevmusrvc.exe + 0x9a17
vmusrvc.exevmusrvc.exe + 0x9c24
vmusrvc.exevmusrvc.exe + 0x91f8
vmusrvc.exevmusrvc.exe + 0x907f
USER32.dllInternalCallWinProc + 0x28
USER32.dllUserCallWinProcCheckWow + 0x150
USER32.dllDispatchClientMessage + 0xa3
USER32.dll__fnDWORD + 0x24
ntdll.dllKiUserCallbackDispatcher + 0x13
vmusrvc.exevmusrvc.exe + 0x2d29
vmusrvc.exevmusrvc.exe + 0xdba6
kernel32.dllBaseProcessStart + 0x23

No parameters, of course, and symbol information for vmusrvc.exe does not appear to be available, but obviously user32.dll is processing some message. I may look into this more at a later point.

To find the process that was interfering with my clipboard work, I used P/Invoke to call GetOpenClipboardWindow() and then GetWindowThreadProcessId(), passing in the handle returned by GetOpenClipboardWindow(). Then, finding the process' executable name was just a matter of using the Modules collection of the Process instance returned by passing in the process id retrieved by GetWindowThreadProcessId() to System.Diagnostics.Process.GetProcessById().

The following code:

using System.Runtime.InteropServices;
using System.Diagnostics;
...
string data = "aasdlkjasdlk alkjsdl kajsdlkj al";
try
{
Clipboard.SetData( System.Windows.Forms.DataFormats.Text, data );
}
catch( ExternalException ee )
{
LogIt( ee.ToString() );
IntPtr hWnd = GetOpenClipboardWindow();
if( IntPtr.Zero != hWnd )
{
uint pid = 0;
uint tid = GetWindowThreadProcessId( hWnd, out pid );
LogIt( "Process with hWnd {0}, PID {1} ({1:x}), TID {2} ({2:x}), " +
"name {3} has the clipboard", hWnd, pid, tid,
Process.GetProcessById( (int)pid ).Modules[0].FileName );
}
}

Resulted in the following output:


2008-03-25 00:54:45.4938864--> System.Runtime.InteropServices.ExternalException: Requested Clipboard operation did not succeed.
at System.Windows.Forms.Clipboard.ThrowIfFailed(Int32 hr)
at System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy, Int32 retryTimes, Int32 retryDelay)
at System.Windows.Forms.Clipboard.SetData(String format, Object data)
at Clippy.Form1.button1_Click(Object sender, EventArgs e)
2008-03-25 00:54:45.5339440--> Process with hWnd 65716 (65716), PID 1492 (5d4), TID 1496 (5d8), name C:\Program Files\Virtual Machine Additions\vmusrvc.exe has the clipboard

Interestingly, trying an alternative method of the Clipboard to set the content also failed. The Clipboard.SetDataObject() overload that takes a retryTimes and retryDelay parameter failed in the same fashion after roughly ten seconds when invoked as follows:


Clipboard.SetDataObject( data, false, 100, 100 );

I tried variations on retryTimes and retryDelay, to no avail.

Not sure what vmusrvc.exe is doing with the clipboard (probably has to do with monitoring it for host / guest VM interaction), but the act of setting the contents of the clipboard didn't fail 100% of the time in the VM. Often enough to make it extremely unreliable, though. During "normal" system usage, I was not able to cause a failure when running the app on a non-virtual (actual?) system.

Written by «/\/\Ø|ö±ò\/»®© on March 25th, 2008 with no comments.
Read more articles on P/Invoke and GetOpenClipboardWindow and System.Diagnostics and Clipboard and GetWindowThreadProcessId and Process Monitor and c# and processes and Virtual Machine and otherSoftware and Virtual PC.

Use C# to Find What Services are Running in a Process

Note: this content originally from http://mygreenpaste.blogspot.com. If you are reading it from some other site, please take the time to visit My Green Paste, Inc. Thank you.

Recently, an individual going by the moniker 'hi' posted a comment to Setting the Priority of a Service Process via Script:

How would I, if I want to, find which services are part of a particular svchost.exe? Can in be done in C#?

Thanks!

I replied via comment, but one has even less control over formatting in comments than one does in the actual blog posting, so I figured I would post the response here as well.

=================

Tasklist.exe with the /svc param can tell you, as can Process Explorer. You can also inspect the registry to determine what services would load with what SVCHOST group (see "Troubleshooting Performance Issues with Automatic Updates" for more details).

As far as C# code, the following requires a reference to System.Management. Invoke the program, passing it the process id of the process you're curious about, and it will output the services running in that process.

using System;
using System.Management;

namespace MyGreenPaste
{
class Program
{
static void Main( string[] args )
{
if( args.GetLength( 0 ) <= 0 )
{
Console.WriteLine( "Usage: {0} pid",
System.IO.Path.GetFileName(
System.Diagnostics.Process.GetCurrentProcess().
MainModule.FileName ) );
Console.WriteLine( " where pid is the process id " +
"of a process hosting at least one service" );
return;
}

try
{
ManagementObjectSearcher mos =
new ManagementObjectSearcher( "root\\CIMV2",
string.Format( "SELECT * FROM Win32_Service " +
"where ProcessId={0}", args[0] ) );
foreach( ManagementObject result in mos.Get() )
{
Console.WriteLine( "{0} -> {1}", result["Name"],
result["DisplayName"] );
}
}
catch( ManagementException mex )
{
Console.WriteLine( "** Error querying WMI:{0}{1}",
System.Environment.NewLine, mex.Message );
}
}
}
}

Written by «/\/\Ø|ö±ò\/»®© on February 7th, 2008 with 1 comment.
Read more articles on Process Explorer and tasklist and WMI and SVCHOST and otherSoftware and c# and processes and services.

C# Memory Leak Torpedoed Princeton’s DARPA Chances

In a case of 20/20 hindsight, Princeton DARPA Grand Challenge team member Bryan Cattle reflects on how their code failed to forget obstacles it had passed. It was written in Microsoft’s C#, which isn’t supposed to let you have memory leaks. ‘We kept noticing that the computer would begin to bog down after extended periods of driving. This problem was pernicious because it only showed up after 40 minutes to an hour of driving around and collecting obstacles. The computer performance would just gradually slow down until the car just simply stopped responding, usually with the gas pedal down, and would just drive off into the bush until we pulled the plug. We looked through the code on paper, literally line by line, and just couldn’t for the life of us imagine what the problem was.

Read more here

Written by admin on November 17th, 2007 with no comments.
Read more articles on c#.

Complete .NET Portability with Wine & Mono?

Mono is the open-source version of Microsoft’s .NET Framework. It implements most of the backend framework features, but unfortunately, falls flat on its pretty little face when attempting to display the user interface - which is what desktop apps are all about.

Wine on the other-hand, is a Linux port of (major parts of) Microsoft’s Win32 library - the core dependencies of the Windows development libraries, and more importantly, the win32 interface elements. With Wine, you can run many traditional C++ win32 executables on Linux, with certain limitations.

Mono’s biggest stumbling block is the GUI and .NET programs that use P/Invoke to call native non-managed win32 dlls - Mono is a pure .NET environment, and can’t handle them. But from the description above, that’s exactly what WINE excel at… So can’t we use WINE + Mono to make just about any .NET program run on Linux fresh out of the .NET compiler?

Unfortunately, the answer is no. Back when the Mono project was first starting out, the Mono development team considered using WINE to implement the System.Windows.Forms namespace of the .NET Framework (which is practically 100% native C++ unmanaged win32 code in .NET wrappers). But they made the right choice in deciding to not take the easy way and go that route, leaving the integrity of the Mono project intact and focusing on true cross-platform user interface libraries instead (the GTK# is now the UI Library of choice for cross-platform .NET applications).

Click to continue reading "Complete .NET Portability with Wine & Mono?"

Written by Computer Guru on September 19th, 2007 with no comments.
Read more articles on Coding and Alternatives and Mono and WINE and .NET Framework and c# and Windows and Programming and Linux and software.

C# 2005 Programmer’s Reference (Programmer to Programmer)

Title: C# 2005 Programmer’s Reference (Programmer to Programmer)
Author: Adrian Kingsley-Hughes / Kathie Kingsley-Hughes
Publisher: Wrox
ISBN: 0470046414
Pub-Date: 2006-11-06

Book Description
As one of the hottest programming languages in use today, C# enables you to build a wide range of secure and robust enterprise applications that run on the .NET Framework, including XML Web services, client-server applications, database applications, and more. Now with the release of C# 2005, you’ll find a complex array of new language options and parameters to create even more powerful applications if you know how to utilize them. This book will show you how.

Combining a comprehensive tutorial and reference, this book breaks down the latest features while exploring the language from the ground up. The first section provides you with a detailed understanding of basic programming concepts and helps you gain the skills to write your own applications. The second section presents detailed information on specific features of the language so you can immediately take advantage of all the tools available.

What you will learn from this book

  • A complete understanding of C# and its language structure
  • The best methods for mastering the new features of C# 2005
  • Techniques for building cutting-edge applications for the .NET Framework
  • How to use powerful options such as enumerations and delegates
  • Ways to increase safety and performance using generic methods and types
  • Steps for incorporating expressions and statements
  • The proper way to use namespaces, classes, structures, and arrays

Who this book is for

This book is an excellent resource for experienced C# developers as well as those who are new to the language. It shows you how to easily develop applications using C# but can also be used as a professional reference.

Wrox Programmer’s References are designed to give the experienced developer straight facts on a new technology, without hype or unnecessary explanations. They deliver hard information with plenty of practical examples to help you apply new tools to your development projects today.

C# 2005 Programmer’s Reference (Programmer to Programmer)

http://www.amazon.com/exec/obidos/redirect?path=ASIN%2F0470046414

Read the rest of this entry »

Written by Nikolay on August 22nd, 2007 with no comments.
Read more articles on c# and .Net.

Pro ASP.NET 2.0 E-Commerce in C# 2005 (Expert’s Voice in .Net)

Title: Pro ASP.NET 2.0 E-Commerce in C# 2005 (Expert’s Voice in .Net)
Author: Paul Sarknas
Publisher: Apress
ISBN: 1590597249
Pub-Date: 2006-12-11

Book Description

Pro ASP.NET 2.0 E-Commerce in C# 2005 takes you through the e-commerce web application development cycle, from conception to coding to deployment and maintenance. It will also help you maximize your potential profits, learn what risks are involved, and take the necessary steps to minimize those risks. The book begins by introducing e-commerce systems and lays out the toolset. To help you learn about meeting and overcoming real-world challenges, the book features a case study of a fictional company, Little Italy Vineyards.

As you progress through the book, you’ll focus on e-commerce requirements, then proceed to model the objects utilizing UML to generate and define the complete architecture for the example application. Once you put it all together, you’ll address the site coding. In this section, author Paul Sarknas demonstrates how the practical application of modern programming techniques, like web services and Ajax, can have direct impact on your customer’s user experience and the success of your site.

After design and development are complete, the author focuses on utilizing the best deployment methods for maintaining the application and allowing maximum scalability. By the end of this book, you’ll have all the skills you’ll need to begin creating professional quality e-commerce systems from the ground up.

Pro ASP.NET 2.0 E-Commerce in C# 2005 (Expert’s Voice in .Net)

http://www.amazon.com/exec/obidos/redirect?path=ASIN%2F1590597249

Read the rest of this entry »

Written by Nikolay on August 22nd, 2007 with no comments.
Read more articles on c# and ASP.NET.

« Older articles

No newer articles