简体   繁体   中英

C# Console application not working properly on Windows Server (works fine on win XP and win 7)

I am having huge problem with application I made for windows server 2008 R2.

The application works on .NET framework 3.5 , and as far as I know windows server 2008 R2 contains such a framework.

Application itself is pretty massive, it is a server program for registering employees work time, by barcode scanner, then store it in . xml file, it also does update itself from update.xml file every few minutes.

To avoid having this application in focus all the time i used some methods to capture keypressed without focus on application.

So to the base of my problem, application is launching properly, it is also reading codes properly and identifying them, but application is apparently having problem with "break:" and "return", and it simply does not launch one of my methods inside of my program. (it is simple static void method without any arguments)

Do I have to rewrite whole program to make it work without calling methods and all breaks and returns? Or what is the problem. This is quite important for me, deadline is more or less today. I could also add that this application is working perfectly fine on other pc's, and when I'm debugging it on my pc, it also works as intended.

I won't post whole code here, it is simply too massive, but I can post parts of it to help you guys.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Xml;
using System.IO;
using System.Threading;
using System.Data;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using Microsoft.Win32;
using System.Reflection;
using System.Security.AccessControl;

    static void Main()
    {
        var handle = GetConsoleWindow();
        ShowWindow(handle, SW_HIDE);
        appPath = Path.GetDirectoryName(Application.ExecutablePath);

        if (AutoStarter.IsAutoStartEnabled == false)
        {
            AutoStarter.SetAutoStart();
        }

        if (!Directory.Exists(appPath+"\\Raporty"))
        {
            Directory.CreateDirectory(appPath + "\\Raporty");
        }

        if (!File.Exists(appPath+"\\settings.jsn"))
        {
        utworzsetting();
        }
        sprawdzostatniawersje();
        uaktualnij();
        _hookID = SetHook(_proc);
        Application.Run();
        UnhookWindowsHookEx(_hookID);
     }





    private delegate IntPtr LowLevelKeyboardProc(
    int nCode, IntPtr wParam, IntPtr lParam);





    private static IntPtr HookCallback(
        int nCode, IntPtr wParam, IntPtr lParam)
    {
        if (nCode >= 0 && wParam == (IntPtr)WM_KEYDOWN)
        {
            int vkCode = Marshal.ReadInt32(lParam);

            switch (vkCode)
                {
                   case 48:
                     wiersz = "";
                     break;
                   case 49:
                     wiersz += "1";
                     break;
                   case 50:
                     wiersz += "2";
                     break;
                   case 51:
                     wiersz += "3";
                     break;
                   case 52:
                     wiersz += "4";
                     break;
                   case 53:
                     wiersz += "5";
                     break;
                   case 54:
                     wiersz += "6";
                     break;
                   case 55:
                     wiersz += "7";
                     break;
                   case 56:
                     wiersz += "8";
                     break;
                   case 57:
                     wiersz += "9";
                     break;
                   case 13:
                     if (wiersz != null)

a few "If"'s

And finally

                             if (aktualneID != -1) // Jezeli ID znajduje sie bazie danych
                         {
                             // MySettings settings = MySettings.Load(appPath + "\\settings.jsn");
                             if (settings.limit == true && lPracownik[aktualneID].Dni.Count != 0)
                             {
                                 czymoze();
                                 if (niemoze == false)
                                 {
                                     Console.WriteLine("z limitem");
                                     asdf();
                                     Console.WriteLine("nie wywolalem metody");
                                 }
                             }
                             else
                             {
                                 Console.WriteLine("bez limitu");
                                 asdf();
                                 Console.WriteLine("nie wywolalem metody");
                             }
                         }
                     }
                            wiersz = "";
                            zapiszbaze();
                     break;
                   default:
                     break;

This is where is the problem, application goes to this moment "Console.WriteLine("bez limitu");" and that's it, it doesn't launch " asdf " method, it also doesn't go for wiersz = "";

I would appreciate any help, if you have any more questions, wants me to specify some things just tell.

PS. I am using VS 2010 Express , if you think that you can help me, I could send you entire solution.

问题解决了,这是.NET Framework故障,我已经将其重新安装在服务器上,并且一切正常。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM