Showing posts with label .NET Framework. Show all posts
Showing posts with label .NET Framework. Show all posts

25 April, 2018

Forcing A Windows Application To Quit On Exit

English: Graphic which hints to Microsoft Windows
English: Graphic which hints to Microsoft Windows (Photo credit: Wikipedia)
25-April-2018

Forcing A Windows Application To Quit On Exit. That was my recent problem with a Windows Forms Application I was finalizing for deployment. It is not a big program. And it is not even one that is complicated. Straightforward and simple. That's what it is. But somehow, it carried a bug.

The .exe isn't terminated by Windows. It remains in the system. I can see it using Task Manager. And how did I find out about it? I am not able to execute a Ctrl-F5 properly. I always get an error.

That is when I started checking here and there, and I found out, the program's .exe remained in the system even after I close the program. Why is that? Beats me!

I opened one of my Windows Forms program, compared the code side-by-side, and no, there is nothing different. It is the same lines of code for the 2 programs, but the former closes and system disposes of everything. The latter, no. the Form closes, but the .exe remains in the system. So I can't start a new program since to the system, it is 'still running'!

Why it behaves that way, I do not know.

Now, I said this is a piece of cake. It is easy. I know how to terminate a program so that it is removed from the Taskbar. I was thinking that the same trick should work on this new program. I mean, why shouldn't it?

But I was wrong. It did not work! How can Visual Studio codes be so quirky?

Anyway, I did some direct codes, testing a few lines a couple of times. And guess what? Here's what worked:

Application.DoEvents();
if (Application.MessageLoop) {
    // WinForms app
    Application.DoEvents();
    Application.Exit();
}
else {
    // Console app
    Environment.Exit(0);
}

That 'if' section, it is meant to be for Windows Forms applications, and the 'else' clause, that is meant to be for non-Windows forms programs, like a Console application. That's the 'normal' way of things. Supposedly the 'right' logic.

But wait.

After trying it the normal way, it didn't work. So I tried it the extra-normal way: use Environment.Exit(0) in my Windows Forms application. And you'll guess it already. It worked!

I guess that is an experienced programmer's edge over the newbie. Not all the time, things work normally. And when it happens, the veteran knows how it is done rightfully, or maverick.

So I hope that you have learned a new thing today: Forcing A Windows Application To Quit On Exit.

Till then!


[Drafted on 26-March-2018]


23 November, 2014

Printing problem in Crystal Reports for VS2005 - SOLVED!

Crystal Reports
Crystal Reports (Photo credit: Wikipedia)
23-Nov-2014


A week or so ago, I had my old work desktop PC formatted and installed with Windows 7. I opted for that because I don't want any leftovers from previous users cluttering up my work. Say I'm fussy, but that is me. At least I can safely say, if ever the time comes that I leave the company, that they can format the hard disk drive, without ever worrying about 'others' having leftover files in the HDD of the PC that I used for X number of years.

Now, that new Windows 7 OS is sure better than XP Professional SP3, and while I am able to make use of the better hardware and better OS, in that the very reason why I had the Windows 7 installed after a format is that the hardware is better, even when it was running Windows XP. Yap, there was another desktop PC involved. I had a swap. I had the faster PC for a swap, and requested for a total clean sweep of the hard disk, which mandated the installation of Windows 7. I didn't know that, but it was a pleasant surprise - when I was told that due to the formatting of the hard disk, I will now be getting Windows 7 instead of Windows XP. I said, "Err... okay!"

When all applications have been reinstalled back, I discovered that the main software I use in my daily work is getting a problem: it wasn't able to run Crystal Reports, or to be precise, all sections work, except the Crystal Reports form.

When that problem was fixed, a new one came about: printing function. All else, like exporting, viewing pages, etc., work. I was stuck, as again, printing the generated report was a mandatory part of the process flow that I call work.

I asked for help, which didn't easily come. I figure, I had to do it on my own. And that was even harder because I don't have internet access at work. I should say it is hard, but I feel safer and more comfortable, with much ado about wasting time browsing while working, etc., etc. So I do my web seraching at home, then attempt all solutions and resolutions when I come back to the office.

To cut to the chase, here's what I did, and unfortunately, I am not quite sure on the exact item that fixed the problem. And yes, I am using Windows 7 64-bit OS. Sadly, some of the articles that I checked insisted that it has nothing to do with the bit-ness of the OS of the client, or the local PC, but the bit-ness of the server. That is contrary to my experience.

  1. I turned on .NET Framework 3.5 through the Control Panel, Turning Windows features on or off.
  2. I installed ReportViewer.exe
  3. I installed cr_net_2005_x86.msi
  4. I installed CRRedist2005_x86.msi
  5. I installed CRRedist2005_X64.msi

Five items, and I didn't know which one did the fix. So I suggest that if you are following my method, help me out by doing one-by-one, and noting which one does the fix, so I can update my post.

Hope this helps somebody, as it did me.

Till then!

17 October, 2013

Stylesheet folder or directory - could make or break your web apps

English: CSS rule in Malayalam
English: CSS rule in Malayalam (Photo credit: Wikipedia)
17-October-2013

I have been reading on ASP.NET, so at least I learn something new. I have been coding and coding and coding, and I have become the woodcutter who did not sharpen his axe. And with the slowdown in load (all major projects completed, and pending roll-out only), I have some free time on my hand.

I found an e-book of Beginning ASP.NET 4.5 in C# and VB, and I skipped the chapters that discussed basic web development, but coming to Chapter 3, I found the CSS section a bit of an eye-opener. Not that I know nothing of CSS -- it is something that I have used extensively on my site, but not entirely the optimum way. And what I have just learned, I tried to apply on one of my simple web applications.

Did I find something to blog on?

You betcha!

I am one who always practiced organization, and I just find that the stylesheet file that was created in the process is 'mixing' with the code files. I just didn't like that. So in the middle of streamlining the CSS codes, have done some pages already, I moved the stylesheet to the \App_Code folder. There was no objection in the IDE...

So, I completed migrating all the inline and embedded styles into the Stylesheet file, so they are all in one common place, and this gave me a chance to remove all redundant and duplicate styles. Wow! Just think of the junk I created... And that is just in the simple web apps...

Anyway, having done everything, I now proceeded to test if what I did works.

Surprise, surprise!

In IE, it did not work. I am using IE10, running in Windows 7 Enterprise. The fonts and colors are all using the default values.

I tried it in Maxthon, in most likelihood, the closest browser to IE. The same behaviour was observed.

I now tried Firefox, and the styles came forth, shining through!

But since the majority of browsers used in our company is IE, I have a problem...

I tried defining the font in the individual rule sets, since the * { font: ...} rule doesn't seem to work at all.

No change.

I put the font definition in the body { ... } rule, and still, no effect.

At this point, I now thought of doing one thing: search the web. Search the web for similar issues and of course, the possible solution to my problem.

Found one article that mentioned the problem to be related to some server issues, and also on the folder/directory that keeps the stylesheet file. Spaces must be replaced with underscore (_).

Well, mine is having an underscore (\App_Code\), so I ruled it out.

I stopped for a while, and tried to think some more...

Then, out of a wild guess, I thought of moving the stylesheet file out of \App_Code\ folder, and back into the main folder.

Did that work?

Yes, it did!

So it wasn't the folder having spaces, and it wasn't the server behaving erratically, but simply, and I confess I don't know why (I don't understand it), the problem was simply due to where the stylesheet file was located.

So a few more code corrections, putting back all those definitions [ * { font: ... } ], and making sure all sections work, I published my modified web apps.

Hopefully it is much faster now.

Till then!
Enhanced by Zemanta

17 November, 2011

How to change the Visual Studio 2010 Registered User and Organization

The Microsoft Visual Studio .NET logo.Image via Wikipedia17-Nov-2011

I've been looking at my splash screen and About info, and all the while, I have been just ignoring the registered User and Organization info. Until lately. I thought I should get that info corrected, or, have it show the user and organization to my liking, whatever. Hey, I've come across one forum and one guy actually asked the same question, and he said that if that doesn't change, then whenever errors happen, and dumps are sent, then the user and organization will be Microsoft-Microsoft. I mean, he is saying that correcting those 2 values is to Microsoft's advantage.

Anyway, so many blogs copy from each other, and what's worse, they copy wrongly.

I have tried, and found that only the organization was changed. The company is correctly reflected, but the user remains the same. One blog after another. One article after another. All saying the same thing.

Until today.

I searched, and seems to me that the day is beginning nice.


Goalsontrack


Chinthaka Bandara wrote the same old stuff, and more. From his blog, entitled Changing Visual Studio 2010 Registered User & Organization, I've seen the complete solution to changing the user and organization info, in both the splash screen, and in the About details.

Premise:

During installation, you are not allowed to enter these values, the user and company/organization. These values are picked up from some registry settings.

Having said thus, we will need to modify the registry. So, edit at your own risk!


VS2010 About screen

On a x86 bit (32 bit OS) computer follow the below path:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Registration\UserName
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

On a x64 bit (64 bit OS) computer follow the below path:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Registration\UserName
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization

You can click on the Close button (the Red button with an X on it at the top right of the registry editor windows), but as always, the recommended step to close the windows is through the menu: File > Exit.

Changing the UserName will change the first line in the help about dialog.
Changing the RegisteredOrganization will change the second line in the help about dialog.


VS2010 Splash screen

NOTE: This will reset the IDE settings, so you better do an export settings first, which, of course, you will restore by importing afterwards.

Open up a command prompt.

On a x86 bit (32 bit OS) computer go to below directory:
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE

On a x64 bit (64 bit OS) computer go to below directory:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE

Type "devenv.exe /setup", then hit [Enter].


Did I mention that while doing this, VS2010 IDE should be closed?

Well, if not, then close the IDE, and do again from the start.


Smart Goal Setting Software


Now, when you activate the VS2010 IDE, take note of the spash screen. User and Organization values should now be changed. A couple of minutes later (longer if you have a slow computer), click on About to display VS2010 details, and voila! User and Organization info should also be changed.

For if not, how?

I do not know...

At least the steps here I have tried myself, on several computers, and they didn't fail me.

Till then!

11 November, 2011

Troubleshooting WebSite publishing in Windows 7

Windows logoImage via Wikipedia11-Nov-2011

This is how I found out about the 'BIG' difference between 'COPYING' and 'COMPILING' when publishing a web site, in Windows 7.

  • Follow deployment tutorial from MSDN (compiled web site, published locally)
  • Error: ASP.NET 4.0 application error: Unrecognized attribute 'targetFramework'...
  • Change IIS DefaultAppPool .NET Framework Version to "4.xxx".
  • Error: HTTP Error 500.21 - Internal Server Error
  •  
  • Run "%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -i". This is to correct installation of ASP.NET
  • Error: none; website is displayed correctly, and working.
NOTE: \Framework\vN.xxx\ -> this is according to the version that is installed in your computer.
Check from the following folder: C:\Windows\Microsoft.NET\Framework\

I hope that this will be of help to many developers like me who struggles with using the latest technologies, but get stuck somewhere in the middle, one way or another...

Till then!

Enhanced by Zemanta

21 October, 2011

Employing Windows XP Logon Screen in Windows 7

The welcome screen in Windows 7 beta, which is...Image via Wikipedia
21-October-2011

Yesterday, I spent some 2 hours at our End User Support area, and one of the things that our main guy, the one doing all the OS installation and setup of individual and production PCs and laptops, was the user acceptability of Windows 7 for the general user group.

Mainly, the big difference between Windows 7 and Windows XP is right from the start: the Logon screen.

In Windows XP, users are so used to seeing 3 boxes:
In Windows 7, you don't see the boxes, but you either see the name of the last logged user, and a box for the password, or you get 2 choices: the last logged user, and 'switch user'. Now, laying aside all questions of intelligence and common sense, an average user (and sometimes even a geek) would never try to guess and attempt clicking on the 'switch user' icon. Especially if that is their orientation, don't play-play.

So now you get the picture - will Windows 7 be accepted easily? It is like saying, go into that new house, there are better things there - and the average tenant can't even figure out how to open the gate...


Keystroke Logger and Computer Monitoring Software


Is there a workaround?

I told him I didn't knew about this problem, since in out team, we are on 99.9% single-user PC/laptop usage ratio. But things are different in the production line. And I said I would look it up in the web.
I did find some very simple solutions, applicable to both Windows Vista and Windows 7, and while the approach may be different between the flavors of Windows 7, the effect is the same.

Here goes:
  1. Click on Windows 7 pearl (hey, it isn't a button anymore).
  2. Type secpol.msc and hit [Enter] (that's for Security Policy).
  3. At the left side, click on Local Policies, then on Security Options.
  4. Then at the right side, click any item, then press "i". That brings you to the list of items beginning with "I".
  5. The main item to Enable is: "Interactive logon: Do not display last user name".
  6. Enabling this is optional: "Interactive logon: Do not require CTRL + ALT + DEL". Enabling this means users will immediately see 2 boxes at the logon screen: username and password.
  7. Close window, and we are done.


Applicability:

I managed to apply these to 2 desktop PCs, and my laptop. I'm just happy that with this simple solution, the objective can be met.

As for the laptop, it isn't exactly the same screen, because there is an additional option for logging in: biometrics sensor.

Hopefully, we are helping to get Windows 7 less resisted but more accepted in the line.
Till then!