Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
W

wjp_auhtm

@wjp_auhtm
About
Posts
30
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • a problem about "bool Exists(Predicate<T> match);"
    W wjp_auhtm

    Thanks! I just back from a business trip. I have googled the lambda operator specifies and research it.There are some differences in syntax. In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions. "it can not run", I said, means that, I could not debug the code in .net 2.0. And I just want to konw why it was happened. Thank you.

    C# csharp dotnet regex help

  • a problem about "bool Exists(Predicate<T> match);"
    W wjp_auhtm

    Yes, I can. I just want to konw why I could not debug the code successed in .net 2.0.

    C# csharp dotnet regex help

  • a problem about "bool Exists(Predicate<T> match);"
    W wjp_auhtm

    Thanks! I have googled the lambda operator specifies and research it.There are some differences in syntax. In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions. Thank you.

    C# csharp dotnet regex help

  • a problem about "bool Exists(Predicate<T> match);"
    W wjp_auhtm

    Thanks! I just back from a business trip. I have googled the lambda operator specifies and research it.There are some differences in syntax. In .net 2.0, it need use delegate to define a virtual method instead of the lambda expressions. Thank you.

    C# csharp dotnet regex help

  • a problem about "bool Exists(Predicate<T> match);"
    W wjp_auhtm

    Thanks! There is another problem. The parameter "b" whose type as same as parameter "item" is not defined. And the parameter "b" have not defined anywhere. I try to change the name of parameter "b" to "a",it also could run. I am puzzled about this.

    C# csharp dotnet regex help

  • a problem about "bool Exists(Predicate<T> match);"
    W wjp_auhtm

    I am trying to convert some code to .net framework 2.0 from .net framework 3.0. the code of .net framework 3.5 is:

    if (mItems.Exists(b => string.Compare(b.FileName, item.FileName, StringComparison.OrdinalIgnoreCase) == 0))
    return;

    It can run in .net framework 3.5 and can not run in .net framework 2.0. Could someone tell me where the defferent things between 3.5 from 2.0 in the code are.

    C# csharp dotnet regex help

  • windows not in focus
    W wjp_auhtm

    I.C. But, just remind once. I know little about the Logging, I will have some research about that.

    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    The function "IsRunning" will check if the windows service is running. I think that when creating a windows service just like creating a application, so I do not know how to create it programatically. We must set the windows service before we release it.

    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    OK, the simple code to check if the service is running like this.

            /// <summary>
            /// TODO: Is the windows service running.
            /// </summary>
            /// <param name="name">The name of windows service.</param>
            private bool IsRunning(string name)
            {
                bool IsRun = false;
                if (!isServiceIsExisted(name)) // this function was named previously.
                {
                    return false;
                }
                ServiceController sc = new ServiceController(name);
                if (sc.Status == ServiceControllerStatus.StartPending ||
                    sc.Status == ServiceControllerStatus.Running)
                {
                    IsRun = true;
                }
                sc.Close();
    
                return IsRun;
            }
    

    Set the service to start automatically: Change the value of property named "StartType" of the windows service to "Automatic". BTW, owing to the limitation of my knowledge, the code are not very strong.I suggest that you can research them by yourself. I think that after you reserach them, you will learn more.

    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    If set the windows service autorun, when you restart computer, the service will start. Of course, you can start the service in manual like this.

            /// <summary>
            /// TODO: Start windows service.
            /// </summary>
            /// <param name="name">The name of windows service.</param>
            /// <returns>If success return true,or return false.;</returns>
            private bool StarmyService(string name)
            {
                ServiceController sc = new ServiceController(name);
                if (sc.Status == ServiceControllerStatus.Stopped || sc.Status == ServiceControllerStatus.StopPending
                        )
                {
                    sc.Start();
                    sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10));
                }
                else
                {
                }
                sc.Close();
                return true;
            }
    

    And stop the service like this

            /// <summary>
            /// TODO: Stop windows service.
            /// </summary>
            /// <param name="name">The name of windows service.</param>
            /// <returns>If success return true,or return false.;</returns>
            private bool StopmyService(string name)
            {
                ServiceController sc = new ServiceController(name);
                if (sc.Status == ServiceControllerStatus.Running ||
                    sc.Status == ServiceControllerStatus.StartPending)
                {
                    sc.Stop();
                    sc.WaitForStatus(ServiceControllerStatus.Stopped, new TimeSpan(0, 0, 10));
                }
                else
                {
                }
                sc.Close();
                return true;
            }
    
    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    You could install the windows service like this, if u are using .Net FrameWork 3.5. I found that the file named "System.Configuration.Install.dll" in .Net 2.0 is different from the .Net 3.5's. There are some simple code.

    using System.ServiceProcess;
    using System.Configuration.Install;
    using System.Collections;

            /// <summary>
            /// TODO: Is the service is existed and return true or false.
            /// </summary>
            /// <param name=" NameService ">Name of the windows service.</param>
            /// <returns>If the service is existed then return true,or return false.</returns>
            private bool isServiceIsExisted(string NameService) 
            {
                ServiceController\[\] services = ServiceController.GetServices();
                foreach (ServiceController s in services) 
                {
                    if (s.ServiceName.ToLower() == NameService.ToLower()) 
                    {
                        return true;
                    }
                }
                return false;
            }
    
            /// <summary>
            /// TODO: Install windows service.
            /// </summary>
            /// <param name="stateSaver">Collection(default is Null)</param>
            /// <param name="filepath">Full path of the windows service file</param>
            private void InstallmyService(IDictionary stateSaver, string filepath)
            {
                AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
                AssemblyInstaller1.UseNewContext = true;
                AssemblyInstaller1.Path = filepath;
                AssemblyInstaller1.Install(stateSaver);
                AssemblyInstaller1.Commit(stateSaver);
                AssemblyInstaller1.Dispose();
            }
            /// <summary>
            /// TODO: Uninstall windows service.
            /// </summary>
            /// <param name="filepath">Full path of the windows service file</param>
            private void UnInstallmyService(string filepath)
            {
                AssemblyInstaller AssemblyInstaller1 = new AssemblyInstaller();
                AssemblyInstaller1.UseNewContext = true;
                AssemblyInstaller1.Path = filepath;
                AssemblyInstaller1.Uninstall(null);
                AssemblyInstaller1.Dispose();
            }
    

    Good Luck!

    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    Yes, it can not instantiation a win form and show it. But I think that the socket could connect the win service and win app.

    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    Oh! I try to open a win app from a windows service, but I was failed. I consider that creating a socket connect between the windows service and the win app may be practicable. creating windows service like this. creating socket like this.

    C# question tutorial

  • windows not in focus
    W wjp_auhtm

    I think that you need create a windows service. When the computer got data, the service app show the data on the form's textbox, even the form unfocused.

    C# question tutorial

  • MultiThread and File process
    W wjp_auhtm

    You can instantiate the class to a variable. Then use the variable which instantiated to open each files. I just write a simple example for you. And, this is only a guiding idea. I consider that the more problems solved by oneself the more he/she learned. There was an old sentence, in our country, said that,"Teaching someone fishing than giving he/she fishes." I suggest that trying each one's answer and google it,I think you will learn more by yourself. I am sorry for my poor English. Good Luck!

    C# help tutorial question

  • MultiThread and File process
    W wjp_auhtm

    Hi: I just write a simple example for you. I hope it was useful for you. /// <summary> /// example of MultiThread /// </summary> class MultiThread { Thread td_example = null; System.Windows.Forms.Control _ctl; public MultiThread(System.Windows.Forms.Control ctl) { td_example = new Thread(new ThreadStart(CalledMethod)); _ctl = ctl; } /// <summary> /// start the thread /// </summary> public void startThread() { td_example.Start(); } /// <summary> /// pause the thread /// </summary> public void suspendThread() { td_example.Suspend(); } /// <summary> /// stop the thread /// Don't forget release the thread by this method /// sometimes, the thread willn't exit and still run after the form closed /// so, I suggest that to call this method before you want to close the main form. /// </summary> public void abortThread() { td_example.Abort(); } int i = 0; private void CalledMethod() { // // TODO:write your code here. // while (true) { i++; System.Windows.Forms.MessageBox.Show(i.ToString()); Thread.Sleep(1000); } } } good luck!

    C# help tutorial question

  • Chinese And English
    W wjp_auhtm

    :)

    The Lounge csharp com learning

  • how to disable close button of windows form
    W wjp_auhtm

    you can do it like this

    this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

    but, you need to write methods such as 'MovingForm'or 'ResizeForm' or something else by yourself.

    C# help tutorial

  • Chinese And English
    W wjp_auhtm

    你好 NightJammer: Nice to meet you!It is true that there are many wise and knowledged people here.Past few days,Beijing was not very hot.Since some rains,the weather is more and more cold. 祝好运! :)

    The Lounge csharp com learning

  • Chinese And English
    W wjp_auhtm

    Hi everybody: I come from China and learning English ,if somebody whose mother Language is English and want to learn Chinese,we can learn from each other. I also a .Net developer on c#. My msn:wjp_auhtm@hotmail.com Thanks! :) wjp_auhtm 9/01

    The Lounge csharp com learning
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups