主頁 > .NET開發 > Quartz與Topshelf結合實作window定時服務

Quartz與Topshelf結合實作window定時服務

2021-10-11 06:19:10 .NET開發

一,新建控制臺應用程式 

二,選中專案,右鍵 — 管理 NuGet 程式包,添加四個:

Quartz

Quartz.Plugins

Topshelf

log4net 

三,創建專案檔案

三個組態檔:必須放在專案根目錄下,

(1)log4net.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>

  <log4net>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <!--日志路徑-->
      <param name= "File" value= https://www.cnblogs.com/wsk198726/p/"Logs/"/>
      <!--是否是向檔案中追加日志-->
      <param name= "AppendToFile" value= https://www.cnblogs.com/wsk198726/p/"true"/>
      <!--log保留天數-->
      <param name= "MaxSizeRollBackups" value= https://www.cnblogs.com/wsk198726/p/"10"/>
      <!--日志檔案名是否是固定不變的-->
      <param name= "StaticLogFileName" value= https://www.cnblogs.com/wsk198726/p/"false"/>
      <!--日志檔案名格式為:yyyy-MM-dd.log-->
      <param name= "DatePattern" value= https://www.cnblogs.com/wsk198726/p/"yyyy-MM-dd&quot;.log&quot;"/>
      <!--日志根據日期滾動-->
      <param name= "RollingStyle" value= https://www.cnblogs.com/wsk198726/p/"Date"/>
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value=https://www.cnblogs.com/wsk198726/p/"[%d{yyyy-MM-dd HH:mm:ss,fff}] [%p] [%c] %m%n %n" />
      </layout>
    </appender>

    <!-- 控制臺前臺顯示日志 -->
    <appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
      <mapping>
        <level value=https://www.cnblogs.com/wsk198726/p/"ERROR" />
        <foreColor value=https://www.cnblogs.com/wsk198726/p/"Red, HighIntensity" />
      </mapping>
      <mapping>
        <level value=https://www.cnblogs.com/wsk198726/p/"Info" />
        <foreColor value=https://www.cnblogs.com/wsk198726/p/"Green" />
      </mapping>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value=https://www.cnblogs.com/wsk198726/p/"%n%date{HH:mm:ss,fff} [%-5level] %m" />
      </layout>

      <filter type="log4net.Filter.LevelRangeFilter">
        <param name="LevelMin" value=https://www.cnblogs.com/wsk198726/p/"Info" />
        <param name="LevelMax" value=https://www.cnblogs.com/wsk198726/p/"Fatal" />
      </filter>
    </appender>

    <root>
      <!--(高) OFF > FATAL > ERROR > WARN > INFO > DEBUG > ALL (低) -->
      <level value=https://www.cnblogs.com/wsk198726/p/"all" />
      <appender-ref ref="ColoredConsoleAppender"/>
      <appender-ref ref="RollingLogFileAppender"/>
    </root>
  </log4net>
</configuration>
View Code

(2)quartz.config 

<?xml version="1.0" encoding="utf-8" ?>
<!-- This file contains job definitions in schema version 2.0 format -->

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>

  <schedule>
    <job>
      <name>SampleJob</name>
      <group>SampleGroup</group>
      <description>Sample job for Quartz Server</description>
      <job-type>QuartzTopshelf.Jobs.SampleJob, QuartzTopshelf</job-type>
      <durable>true</durable>
      <recover>false</recover>
      <job-data-map>
        <entry>
          <key>key1</key>
          <value>value1</value>
        </entry>
        <entry>
          <key>key2</key>
          <value>value2</value>
        </entry>
      </job-data-map>
    </job>

    <trigger>
      <simple>
        <name>SampleSimpleTrigger</name>
        <group>SampleSimpleGroup</group>
        <description>Simple trigger to simply fire sample job</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleGroup</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <repeat-count>-1</repeat-count>
        <repeat-interval>10000</repeat-interval>
      </simple>
    </trigger>
    <trigger>
      <cron>
        <name>SampleCronTrigger</name>
        <group>SampleCronGroup</group>
        <description>Cron trigger to simply fire sample job</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleGroup</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <cron-expression>0/10 * * * * ?</cron-expression>
      </cron>
    </trigger>
    <trigger>
      <calendar-interval>
        <name>SampleCalendarIntervalTrigger</name>
        <group>SampleCalendarIntervalGroup</group>
        <description>Calendar interval trigger to simply fire sample job</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleGroup</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <repeat-interval>15</repeat-interval>
        <repeat-interval-unit>Second</repeat-interval-unit>
      </calendar-interval>
    </trigger>
  </schedule>
</job-scheduling-data>
View Code

也可以在專案組態檔App.config中配置,就不需要配置quartz.config 

App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </configSections>

  <quartz>   
    <add key="quartz.scheduler.instanceName" value=https://www.cnblogs.com/wsk198726/p/"ServerScheduler" />   
    <add key="quartz.threadPool.type" value=https://www.cnblogs.com/wsk198726/p/"Quartz.Simpl.DefaultThreadPool, Quartz" />
    <add key="quartz.threadPool.maxConcurrency" value=https://www.cnblogs.com/wsk198726/p/"10" />

    <add key="quartz.plugin.xml.type" value=https://www.cnblogs.com/wsk198726/p/"Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz.Plugins" />
    <add key="quartz.plugin.xml.fileNames" value=https://www.cnblogs.com/wsk198726/p/"~/quartz_jobs.xml" />

    <add key="quartz.scheduler.exporter.type" value=https://www.cnblogs.com/wsk198726/p/"Quartz.Simpl.RemotingSchedulerExporter, Quartz" />
    <add key="quartz.scheduler.exporter.port" value=https://www.cnblogs.com/wsk198726/p/"555" />
    <add key="quartz.scheduler.exporter.bindName" value=https://www.cnblogs.com/wsk198726/p/"QuartzScheduler" />
    <add key="quartz.scheduler.exporter.channelType" value=https://www.cnblogs.com/wsk198726/p/"tcp" />
    <add key="quartz.scheduler.exporter.channelName" value=https://www.cnblogs.com/wsk198726/p/"httpQuartz" />
  </quartz> 
  
  <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
  
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
View Code

(3)quartz_jobs.xml   具體我就不解釋了,不懂的可以去查下Quartz.NET

<?xml version="1.0" encoding="utf-8" ?>
<!-- This file contains job definitions in schema version 2.0 format -->

<job-scheduling-data xmlns="http://quartznet.sourceforge.net/JobSchedulingData" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0">
  <processing-directives>
    <overwrite-existing-data>true</overwrite-existing-data>
  </processing-directives>

  <schedule>
    <job>
      <name>SampleJob</name>
      <group>SampleGroup</group>
      <description>Sample job for Quartz Server</description>
      <job-type>Quartz.Server.Jobs.SampleJob, Quartz.Server</job-type>
      <durable>true</durable>
      <recover>false</recover>
      <job-data-map>
        <entry>
          <key>key1</key>
          <value>value1</value>
        </entry>
        <entry>
          <key>key2</key>
          <value>value2</value>
        </entry>
      </job-data-map>
    </job>

    <trigger>
      <simple>
        <name>SampleSimpleTrigger</name>
        <group>SampleSimpleGroup</group>
        <description>Simple trigger to simply fire sample job</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleGroup</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <repeat-count>-1</repeat-count>
        <repeat-interval>10000</repeat-interval>
      </simple>
    </trigger>
    <trigger>
      <cron>
        <name>SampleCronTrigger</name>
        <group>SampleCronGroup</group>
        <description>Cron trigger to simply fire sample job</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleGroup</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <cron-expression>0/10 * * * * ?</cron-expression>
      </cron>
    </trigger>
    <trigger>
      <calendar-interval>
        <name>SampleCalendarIntervalTrigger</name>
        <group>SampleCalendarIntervalGroup</group>
        <description>Calendar interval trigger to simply fire sample job</description>
        <job-name>SampleJob</job-name>
        <job-group>SampleGroup</job-group>
        <misfire-instruction>SmartPolicy</misfire-instruction>
        <repeat-interval>15</repeat-interval>
        <repeat-interval-unit>Second</repeat-interval-unit>
      </calendar-interval>
    </trigger>

  </schedule>
</job-scheduling-data>
View Code

三個類檔案:

(1)Configuration.cs  配置類

using System.Collections.Specialized;
using System.Configuration;

namespace QuartzTopshelf
{
    /// <summary>
    /// 定時服務的配置
    /// </summary>
    public class Configuration
    {
        private const string PrefixServerConfiguration = "quartz.server";
        private const string KeyServiceName = PrefixServerConfiguration + ".serviceName";
        private const string KeyServiceDisplayName = PrefixServerConfiguration + ".serviceDisplayName";
        private const string KeyServiceDescription = PrefixServerConfiguration + ".serviceDescription";
        private const string KeyServerImplementationType = PrefixServerConfiguration + ".type";

        private const string DefaultServiceName = "QuartzServer";
        private const string DefaultServiceDisplayName = "Quartz Server";
        private const string DefaultServiceDescription = "Quartz Job Scheduling Server";
        private static readonly string DefaultServerImplementationType = typeof(QuartzServer).AssemblyQualifiedName;

        private static readonly NameValueCollection configuration;

        /// <summary>
        /// 初始化 Configuration 類
        /// </summary>
        static Configuration()
        {
            configuration = (NameValueCollection)ConfigurationManager.GetSection("quartz");
        }

        /// <summary>
        /// 獲取服務的名稱
        /// </summary>
        /// <value>服務的名稱</value>
        public static string ServiceName
        {
            get { return GetConfigurationOrDefault(KeyServiceName, DefaultServiceName); }
        }

        /// <summary>
        /// 獲取服務的顯示名稱.
        /// </summary>
        /// <value>服務的顯示名稱</value>
        public static string ServiceDisplayName
        {
            get { return GetConfigurationOrDefault(KeyServiceDisplayName, DefaultServiceDisplayName); }
        }

        /// <summary>
        /// 獲取服務描述
        /// </summary>
        /// <value>服務描述</value>
        public static string ServiceDescription
        {
            get { return GetConfigurationOrDefault(KeyServiceDescription, DefaultServiceDescription); }
        }

        /// <summary>
        /// 獲取服務器實作的型別名稱
        /// </summary>
        /// <value>服務器實作的型別</value>
        public static string ServerImplementationType
        {
            get { return GetConfigurationOrDefault(KeyServerImplementationType, DefaultServerImplementationType); }
        }

        /// <summary>
        /// 回傳具有給定鍵的配置值,如果的配置不存在,則回傳默認值,
        /// </summary>
        /// <param name="configurationKey">用于讀取配置的鍵</param>
        /// <param name="defaultValue">未找到配置時回傳的默認值</param>
        /// <returns>配置值</returns>
        private static string GetConfigurationOrDefault(string configurationKey, string defaultValue)
        {
            string retValue = https://www.cnblogs.com/wsk198726/p/null;
            if (configuration != null)
            {
                retValue = configuration[configurationKey];
            }

            if (retValue =https://www.cnblogs.com/wsk198726/p/= null || retValue.Trim().Length == 0)
            {
                retValue = defaultValue;
            }
            return retValue;
        }
    }
}
View Code

(2)QuartzServer.cs  定時服務類

using System;
using System.Threading.Tasks;
using log4net;
using Quartz;
using Quartz.Impl;
using Topshelf;

namespace QuartzTopshelf
{
    /// <summary>
    /// Service interface for core Quartz.NET server.
    /// </summary>
    public interface IQuartzServer
    {
        /// <summary>
        /// Initializes the instance of <see cref="IQuartzServer"/>.
        /// Initialization will only be called once in server's lifetime.
        /// </summary>
        Task Initialize();

        /// <summary>
        /// Starts this instance.
        /// </summary>
        void Start();

        /// <summary>
        /// Stops this instance.
        /// </summary>
        void Stop();

        /// <summary>
        /// Pauses all activity in scheduler.
        /// </summary>
        void Pause();

        /// <summary>
        /// Resumes all activity in server.
        /// </summary>
        void Resume();
    }

    /// <summary>
    /// The main server logic.
    /// </summary>
    public class QuartzServer : ServiceControl, IQuartzServer
    {
        private readonly ILog logger;
        private ISchedulerFactory schedulerFactory;
        private IScheduler scheduler;

        /// <summary>
        /// Initializes a new instance of the <see cref="QuartzServer"/> class.
        /// </summary>
        public QuartzServer()
        {
            logger = LogManager.GetLogger(GetType());
        }

        /// <summary>
        /// Initializes the instance of the <see cref="QuartzServer"/> class.
        /// </summary>
        public virtual async Task Initialize()
        {
            try
            {
                schedulerFactory = CreateSchedulerFactory();
                scheduler = await GetScheduler().ConfigureAwait(false);
            }
            catch (Exception e)
            {
                logger.Error("Server initialization failed:" + e.Message, e);
            }
        }

        /// <summary>
        /// Gets the scheduler with which this server should operate with.
        /// </summary>
        /// <returns></returns>
        protected virtual Task<IScheduler> GetScheduler()
        {
            return schedulerFactory.GetScheduler();
        }

        /// <summary>
        /// Returns the current scheduler instance (usually created in <see cref="Initialize" />
        /// using the <see cref="GetScheduler" /> method).
        /// </summary>
        protected virtual IScheduler Scheduler => scheduler;

        /// <summary>
        /// Creates the scheduler factory that will be the factory
        /// for all schedulers on this instance.
        /// </summary>
        /// <returns></returns>
        protected virtual ISchedulerFactory CreateSchedulerFactory()
        {
            return new StdSchedulerFactory();
        }

        /// <summary>
        /// Starts this instance, delegates to scheduler.
        /// </summary>
        public virtual void Start()
        {
            try
            {
                scheduler.Start();
            }
            catch (Exception ex)
            {
                logger.Fatal(string.Format("Scheduler start failed: {0}", ex.Message), ex);
                throw;
            }
            //logger.Info("Scheduler started successfully");
        }

        /// <summary>
        /// Stops this instance, delegates to scheduler.
        /// </summary>
        public virtual void Stop()
        {
            try
            {
                scheduler.Shutdown(true);
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("Scheduler stop failed: {0}", ex.Message), ex);
                throw;
            }

            //logger.Info("Scheduler shutdown complete");
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public virtual void Dispose()
        {
            // no-op for now
        }

        /// <summary>
        /// Pauses all activity in scheduler.
        /// </summary>
        public virtual void Pause()
        {
            scheduler.PauseAll();
        }

        /// <summary>
        /// Resumes all activity in server.
        /// </summary>
        public void Resume()
        {
            scheduler.ResumeAll();
        }

        /// <summary>
        /// TopShelf's method delegated to <see cref="Start()"/>.
        /// </summary>
        public bool Start(HostControl hostControl)
        {
            Start();
            return true;
        }

        /// <summary>
        /// TopShelf's method delegated to <see cref="Stop()"/>.
        /// </summary>
        public bool Stop(HostControl hostControl)
        {
            Stop();
            return true;
        }

        /// <summary>
        /// TopShelf's method delegated to <see cref="Pause()"/>.
        /// </summary>
        public bool Pause(HostControl hostControl)
        {
            Pause();
            return true;
        }

        /// <summary>
        /// TopShelf's method delegated to <see cref="Resume()"/>.
        /// </summary>
        public bool Continue(HostControl hostControl)
        {
            Resume();
            return true;
        }
    }
}
View Code

(3)QuartzServerFactory.cs  工廠類

using System;
using System.Reflection;
using log4net;

namespace QuartzTopshelf
{
    /// <summary>
    /// 用于創建Quartz服務實作的工廠類.
    /// </summary>
    public class QuartzServerFactory
    {
        private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 創建Quartz.NET服務核心的新實體
        /// </summary>
        /// <returns></returns>
        public static QuartzServer CreateServer()
        {
            string typeName = Configuration.ServerImplementationType;

            Type t = Type.GetType(typeName, true);

            //logger.Debug("正在創建服務器型別的新實體'" + typeName + "'");
            QuartzServer retValue =https://www.cnblogs.com/wsk198726/p/ (QuartzServer)Activator.CreateInstance(t);
            //logger.Debug("已成功創建實體");
            return retValue;
        }
    }
}
View Code

服務啟動類:Program.cs

using System.IO;
using System.Reflection;
using Topshelf;

namespace QuartzTopshelf
{
    public static class Program
    {
        static void Main(string[] args)
        {
            // 從服務帳戶的目錄更改為更符合邏輯的目錄
            Directory.SetCurrentDirectory(System.AppDomain.CurrentDomain.BaseDirectory);

            var logRepository = log4net.LogManager.GetRepository(Assembly.GetEntryAssembly());
            log4net.Config.XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

            HostFactory.Run(x => {
                x.RunAsLocalSystem();

                x.SetDescription(Configuration.ServiceDescription);
                x.SetDisplayName(Configuration.ServiceDisplayName);
                x.SetServiceName(Configuration.ServiceName);

                x.Service(factory =>
                {
                    QuartzServer server = QuartzServerFactory.CreateServer();
                    server.Initialize().GetAwaiter().GetResult();
                    return server;
                });
            });
        }
    }
}
View Code

四,添加Job類,以及在quartz_jobs.xml 配置job作業觸發規則

SampleJob.cs

using System;
using System.Collections;
using System.Reflection;
using System.Threading.Tasks;
using log4net;
using Quartz;

namespace QuartzTopshelf.Jobs
{
    /// <summary>
    /// A sample job that just prints info on console for demostration purposes.
    /// </summary>
    public sealed class SampleJob : IJob
    {
        private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// Called by the <see cref="IScheduler" /> when a <see cref="ITrigger" />
        /// fires that is associated with the <see cref="IJob" />.
        /// </summary>
        /// <remarks>
        /// The implementation may wish to set a  result object on the 
        /// JobExecutionContext before this method exits.  The result itself
        /// is meaningless to Quartz, but may be informative to 
        /// <see cref="IJobListener" />s or 
        /// <see cref="ITriggerListener" />s that are watching the job's 
        /// execution.
        /// </remarks>
        /// <param name="context">The execution context.</param>
        public async Task Execute(IJobExecutionContext context)
        {
            //通過組態檔傳遞引數
            JobDataMap dataMap = context.JobDetail.JobDataMap;
            string key1 = dataMap.GetString("key1");
            logger.Info("key1 : " + key1);
            string key2 = dataMap.GetString("key2");
            logger.Info("key2 : " + key2);

            logger.Info("SampleJob running...");
            //Thread.Sleep(TimeSpan.FromSeconds(5));
            await Console.Out.WriteLineAsync("SampleJob is executing.");
            logger.Info("SampleJob run finished.");
        }
    }
}
View Code

作業觸發規則在上面quartz_jobs.xml檔案中配置 

這里分析下特別提到下,job的trigger有以下幾種常用的方法:

  • SimpleTrigger:簡單的觸發器(重點)

  • CalendarIntervalTrigger:日歷觸發器(可自行研究)

  • CronTrigger:Cron運算式觸發器 (重點)

 

 專案結構圖:

另外可以通過組態檔設定引數傳遞給作業:

 

 


相關源代碼地址:https://gitee.com/wyft/QuartzTopshelf 

 

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/308036.html

標籤:C#

上一篇:.NET C# 獲取免費代理IP

下一篇:C# 加載Word的3種方法

標籤雲
其他(157675) Python(38076) JavaScript(25376) Java(17977) C(15215) 區塊鏈(8255) C#(7972) AI(7469) 爪哇(7425) MySQL(7132) html(6777) 基礎類(6313) sql(6102) 熊猫(6058) PHP(5869) 数组(5741) R(5409) Linux(5327) 反应(5209) 腳本語言(PerlPython)(5129) 非技術區(4971) Android(4554) 数据框(4311) css(4259) 节点.js(4032) C語言(3288) json(3245) 列表(3129) 扑(3119) C++語言(3117) 安卓(2998) 打字稿(2995) VBA(2789) Java相關(2746) 疑難問題(2699) 细绳(2522) 單片機工控(2479) iOS(2429) ASP.NET(2402) MongoDB(2323) 麻木的(2285) 正则表达式(2254) 字典(2211) 循环(2198) 迅速(2185) 擅长(2169) 镖(2155) 功能(1967) .NET技术(1958) Web開發(1951) python-3.x(1918) HtmlCss(1915) 弹簧靴(1913) C++(1909) xml(1889) PostgreSQL(1872) .NETCore(1853) 谷歌表格(1846) Unity3D(1843) for循环(1842)

熱門瀏覽
  • WebAPI簡介

    Web體系結構: 有三個核心:資源(resource),URL(統一資源識別符號)和表示 他們的關系是這樣的:一個資源由一個URL進行標識,HTTP客戶端使用URL定位資源,表示是從資源回傳資料,媒體型別是資源回傳的資料格式。 接下來我們說下HTTP. HTTP協議的系統是一種無狀態的方式,使用請求/ ......

    uj5u.com 2020-09-09 22:07:47 more
  • asp.net core 3.1 入口:Program.cs中的Main函式

    本文分析Program.cs 中Main()函式中代碼的運行順序分析asp.net core程式的啟動,重點不是剖析原始碼,而是理清程式開始時執行的順序。到呼叫了哪些實體,哪些法方。asp.net core 3.1 的程式入口在專案Program.cs檔案里,如下。ususing System; us ......

    uj5u.com 2020-09-09 22:07:49 more
  • asp.net網站作為websocket服務端的應用該如何寫

    最近被websocket的一個問題困擾了很久,有一個需求是在web網站中搭建websocket服務。客戶端通過網頁與服務器建立連接,然后服務器根據ip給客戶端網頁發送資訊。 其實,這個需求并不難,只是剛開始對websocket的內容不太了解。上網搜索了一下,有通過asp.net core 實作的、有 ......

    uj5u.com 2020-09-09 22:08:02 more
  • ASP.NET 開源匯入匯出庫Magicodes.IE Docker中使用

    Magicodes.IE在Docker中使用 更新歷史 2019.02.13 【Nuget】版本更新到2.0.2 【匯入】修復單列匯入的Bug,單元測驗“OneColumnImporter_Test”。問題見(https://github.com/dotnetcore/Magicodes.IE/is ......

    uj5u.com 2020-09-09 22:08:05 more
  • 在webform中使用ajax

    如果你用過Asp.net webform, 說明你也算是.NET 開發的老兵了。WEBform應該是2011 2013左右,當時還用visual studio 2005、 visual studio 2008。后來基本都用的是MVC。 如果是新開發的專案,估計沒人會用webform技術。但是有些舊版 ......

    uj5u.com 2020-09-09 22:08:50 more
  • iis添加asp.net網站,訪問提示:由于擴展配置問題而無法提供您請求的

    今天在iis服務器配置asp.net網站,遇到一個問題,記錄一下: 問題:由于擴展配置問題而無法提供您請求的頁面。如果該頁面是腳本,請添加處理程式。如果應下載檔案,請添加 MIME 映射。 WindowServer2012服務器,添加角色安裝完.netframework和iis之后,運行aspx頁面 ......

    uj5u.com 2020-09-09 22:10:00 more
  • WebAPI-處理架構

    帶著問題去思考,大家好! 問題1:HTTP請求和回傳相應的HTTP回應資訊之間發生了什么? 1:首先是最底層,托管層,位于WebAPI和底層HTTP堆疊之間 2:其次是 訊息處理程式管道層,這里比如日志和快取。OWIN的參考是將訊息處理程式管道的一些功能下移到堆疊下端的OWIN中間件了。 3:控制器處理 ......

    uj5u.com 2020-09-09 22:11:13 more
  • 微信門戶開發框架-使用指導說明書

    微信門戶應用管理系統,采用基于 MVC + Bootstrap + Ajax + Enterprise Library的技術路線,界面層采用Boostrap + Metronic組合的前端框架,資料訪問層支持Oracle、SQLServer、MySQL、PostgreSQL等資料庫。框架以MVC5,... ......

    uj5u.com 2020-09-09 22:15:18 more
  • WebAPI-HTTP編程模型

    帶著問題去思考,大家好!它是什么?它包含什么?它能干什么? 訊息 HTTP編程模型的核心就是訊息抽象,表示為:HttPRequestMessage,HttpResponseMessage.用于客戶端和服務端之間交換請求和回應訊息。 HttpMethod類包含了一組靜態屬性: private stat ......

    uj5u.com 2020-09-09 22:15:23 more
  • 部署WebApi隨筆

    一、跨域 NuGet參考Microsoft.AspNet.WebApi.Cors WebApiConfig.cs中配置: // Web API 配置和服務 config.EnableCors(new EnableCorsAttribute("*", "*", "*")); 二、清除默認回傳XML格式 ......

    uj5u.com 2020-09-09 22:15:48 more
最新发布
  • C#多執行緒學習(二) 如何操縱一個執行緒

    <a href="https://www.cnblogs.com/x-zhi/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2943582/20220801082530.png" alt="" /></...

    uj5u.com 2023-04-19 09:17:20 more
  • C#多執行緒學習(二) 如何操縱一個執行緒

    C#多執行緒學習(二) 如何操縱一個執行緒 執行緒學習第一篇:C#多執行緒學習(一) 多執行緒的相關概念 下面我們就動手來創建一個執行緒,使用Thread類創建執行緒時,只需提供執行緒入口即可。(執行緒入口使程式知道該讓這個執行緒干什么事) 在C#中,執行緒入口是通過ThreadStart代理(delegate)來提供的 ......

    uj5u.com 2023-04-19 09:16:49 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    <a href="https://www.cnblogs.com/huangxincheng/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/214741/20200614104537.png" alt="" /&g...

    uj5u.com 2023-04-18 08:39:04 more
  • 記一次 .NET某醫療器械清洗系統 卡死分析

    一:背景 1. 講故事 前段時間協助訓練營里的一位朋友分析了一個程式卡死的問題,回過頭來看這個案例比較經典,這篇稍微整理一下供后來者少踩坑吧。 二:WinDbg 分析 1. 為什么會卡死 因為是表單程式,理所當然就是看主執行緒此時正在做什么? 可以用 ~0s ; k 看一下便知。 0:000> k # ......

    uj5u.com 2023-04-18 08:33:10 more
  • SignalR, No Connection with that ID,IIS

    <a href="https://www.cnblogs.com/smartstar/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/u36196.jpg" alt="" /></a>...

    uj5u.com 2023-03-30 17:21:52 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:15:33 more
  • 一次對pool的誤用導致的.net頻繁gc的診斷分析

    <a href="https://www.cnblogs.com/dotnet-diagnostic/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/3115652/20230225090434.png" alt=""...

    uj5u.com 2023-03-28 10:13:31 more
  • C#遍歷指定檔案夾中所有檔案的3種方法

    <a href="https://www.cnblogs.com/xbhp/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/957602/20230310105611.png" alt="" /></a&...

    uj5u.com 2023-03-27 14:46:55 more
  • C#/VB.NET:如何將PDF轉為PDF/A

    <a href="https://www.cnblogs.com/Carina-baby/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/2859233/20220427162558.png" alt="" />...

    uj5u.com 2023-03-27 14:46:35 more
  • 武裝你的WEBAPI-OData聚合查詢

    <a href="https://www.cnblogs.com/podolski/" target="_blank"><img width="48" height="48" class="pfs" src="https://pic.cnblogs.com/face/616093/20140323000327.png" alt="" /><...

    uj5u.com 2023-03-27 14:46:16 more