主頁 > .NET開發 > WPF源代碼分析系列一:剖析WPF模板機制的內部實作(五)

WPF源代碼分析系列一:剖析WPF模板機制的內部實作(五)

2020-12-19 06:05:44 .NET開發

(注:本文是《剖析WPF模板機制的內部實作》系列文章的最后一篇文章,查看上一篇文章請點這里)

上一篇文章我們討論了DataTemplate型別的兩個重要變數,ContentControl.ContentTemplate和ContentPresenter.ContentTemplate,這一篇將討論這個型別的另一個重要變數ItemsControl.ItemTemplate

4.2ItemsControl.ItemTemplate

我們都知道ItemsControl控制元件在WPF中的重要性,ItemsControl.ItemTemplate用的也非常多,那么其在模板應用中的角色是什么呢?要回答這個問題,我們先看其定義:

    public static readonly DependencyProperty ItemTemplateProperty =
                DependencyProperty.Register(
                        "ItemTemplate",
                        typeof(DataTemplate),
                        typeof(ItemsControl),
                        new FrameworkPropertyMetadata(
                                (DataTemplate) null,
                                OnItemTemplateChanged));

        /// <summary>
        ///     ItemTemplate is the template used to display each item.
        /// </summary>public DataTemplate ItemTemplate
        {
            get { return (DataTemplate) GetValue(ItemTemplateProperty); }
            set { SetValue(ItemTemplateProperty, value); }
        }

        private static void OnItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((ItemsControl) d).OnItemTemplateChanged((DataTemplate) e.OldValue, (DataTemplate) e.NewValue);
        }

        protected virtual void OnItemTemplateChanged(DataTemplate oldItemTemplate, DataTemplate newItemTemplate)
        {
            CheckTemplateSource();
 
            if (_itemContainerGenerator != null)
            {
                _itemContainerGenerator.Refresh();
            }
        }

 可以看到當ItemsControl.ItemTemplate改變時,會呼叫_itemContainerGenerator.Refresh(),這個方法的定義如下:

        // regenerate everything
        internal void Refresh()
        {
            OnRefresh();
        }

        // Called when the items collection is refreshed
        void OnRefresh()
        {
            ((IItemContainerGenerator)this).RemoveAll();

            // tell layout what happened
            if (ItemsChanged != null)
            {
                GeneratorPosition position = new GeneratorPosition(0, 0);
                ItemsChanged(this, new ItemsChangedEventArgs(NotifyCollectionChangedAction.Reset, position, 0, 0));
            }
        }

可見這個方法呼叫OnRefresh(),后者的主要作業是清空已經生成的元素,并觸發ItemsChanged事件,通知所有監聽者串列已經被重置,

查找ItemsControl.ItemTemplate的參考會發現一個值得注意的方法ItemsControl.PrepareContainerForItemOverride

//*********************ItemsControl*************************

/// <summary> /// Prepare the element to display the item. This may involve /// applying styles, setting bindings, etc. /// </summary> protected virtual void PrepareContainerForItemOverride(DependencyObject element, object item) { // Each type of "ItemContainer" element may require its own initialization. // We use explicit polymorphism via internal methods for this. // // Another way would be to define an interface IGeneratedItemContainer with // corresponding virtual "core" methods. Base classes (ContentControl, // ItemsControl, ContentPresenter) would implement the interface // and forward the work to subclasses via the "core" methods. // // While this is better from an OO point of view, and extends to // 3rd-party elements used as containers, it exposes more public API. // Management considers this undesirable, hence the following rather // inelegant code. HeaderedContentControl hcc; ContentControl cc; ContentPresenter cp; ItemsControl ic; HeaderedItemsControl hic; if ((hcc = element as HeaderedContentControl) != null) { hcc.PrepareHeaderedContentControl(item, ItemTemplate, ItemTemplateSelector, ItemStringFormat); } else if ((cc = element as ContentControl) != null) { cc.PrepareContentControl(item, ItemTemplate, ItemTemplateSelector, ItemStringFormat); } else if ((cp = element as ContentPresenter) != null) { cp.PrepareContentPresenter(item, ItemTemplate, ItemTemplateSelector, ItemStringFormat); } else if ((hic = element as HeaderedItemsControl) != null) { hic.PrepareHeaderedItemsControl(item, this); } else if ((ic = element as ItemsControl) != null) { if (ic != this) { ic.PrepareItemsControl(item, this); } } }

這個方法共兩個引數,第一個引數element的作用是作為第二個引數item的容器(container),這個item實際就是ItemsControl.ItemsSourceIEnumerable型別)串列的資料項,這個方法的主要作業是根據引數element的型別,做一些準備作業:如HeaderedContentControl和HeaderedItemsControl會把ItemTemplate的值賦給HeaderTemplate,而ContentControl和ContentPresenter則會用它更新ContentTemplate,如果是element也是ItemsControl,這意味著一個ItemsControl的ItemTemplate里又嵌套了一個ItemsControl,這時就把父控制元件的ItemTemplate傳遞給子控制元件的ItemTemplate,

現在關鍵的問題是這里的引數element和item到底是怎么來的?要回答這個問題我們需要搞清楚ItemsControl.PrepareContainerForItemOverride()方法是怎么被呼叫的,查看參考可以發現ItemsControl.PrepareItemContainer()方法呼叫了這個方法,其代碼如下:

//**************ItemsControl****************

/// <summary> /// Prepare the element to act as the ItemContainer for the corresponding item. /// </summary> void IGeneratorHost.PrepareItemContainer(DependencyObject container, object item) { // GroupItems are special - their information comes from a different place GroupItem groupItem = container as GroupItem; if (groupItem != null) { groupItem.PrepareItemContainer(item, this); return; } if (ShouldApplyItemContainerStyle(container, item)) { // apply the ItemContainer style (if any) ApplyItemContainerStyle(container, item); } // forward ItemTemplate, et al. PrepareContainerForItemOverride(container, item); .........此處省略**行代碼 }

可以看到這個方法調首先會檢查這個container是否GroupItem型別,如果不是則呼叫PrepareContainerForItemOverride(),并把container作為其第一引數,繼續追蹤這個方法的參考,我們會發現:ItemContainerGenerator類的PrepareItemContainer()呼叫了這個方法:

//*****************ItemContainerGenerator********************
        /// <summary>
        /// Prepare the given element to act as the container for the
        /// corresponding item.  This includes applying the container style,
        /// forwarding information from the host control (ItemTemplate, etc.),
        /// and other small adjustments.
        /// </summary>
        /// <remarks>
        /// This method must be called after the element has been added to the
        /// visual tree, so that resource references and inherited properties
        /// work correctly.
        /// </remarks>
        /// <param name="container"> The container to prepare.
        /// Normally this is the result of the previous call to GenerateNext.
        /// </param>
        void IItemContainerGenerator.PrepareItemContainer(DependencyObject container)
        {
            object item = container.ReadLocalValue(ItemForItemContainerProperty);
            Host.PrepareItemContainer(container, item);
        }

這個方法的注釋講的比較清楚:這個方法的作用是對這個containter做一些預處理作業,包括應用樣式,“轉交”(forward)一些來自宿主控制元件(我們這個例子是ItemsControl)的資訊(例如ItemTemplate等),為了讓資源參考和依賴屬性繼承正常作業,這個container在被加入visual tree前必須呼叫這個方法,

這個方法的第一個陳述句告訴我們資料項item可以通過container讀取ItemForItemContainerProperty的值獲得,這個屬性是附加屬性,ItemContainerGenerator有一個靜態方法LinkContainerToItem(),是專門用來為每個container設定(連接)這個屬性的:

//*****************ItemContainerGenerator********************

// establish the link from the container to the corresponding item internal static void LinkContainerToItem(DependencyObject container, object item) { // always set the ItemForItemContainer property container.ClearValue(ItemForItemContainerProperty); container.SetValue(ItemForItemContainerProperty, item); // for non-direct items, set the DataContext property if (container != item) { container.SetValue(FrameworkElement.DataContextProperty, item); } }

這個方法在ItemContainerGenerator類內部被多次呼叫,其中關鍵的一次是在其內部類GeneratorGenerateNext()方法,此外這個方法關于引數container的注釋也表明,這個container是通過呼叫GenerateNext()獲得的,因此這個方法無疑是例外重要的,其代碼如下:

//****************ItemContainerGenerator*******************

/// <summary> Generate UI for the next item or group</summary> public DependencyObject GenerateNext(bool stopAtRealized, out bool isNewlyRealized) { DependencyObject container = null; isNewlyRealized = false; while (container == null) { UnrealizedItemBlock uBlock = _cachedState.Block as UnrealizedItemBlock; IList items =_factory.ItemsInternal; int itemIndex = _cachedState.ItemIndex; int incr = (_direction == GeneratorDirection.Forward) ? +1 : -1; if (_cachedState.Block == _factory._itemMap) _done = true; // we've reached the end of the list if (uBlock == null && stopAtRealized) _done = true; if (!(0 <= itemIndex && itemIndex < items.Count)) _done = true; if (_done) { isNewlyRealized = false; return null; } object item = items[itemIndex]; if (uBlock != null) { // We don't have a realized container for this item. Try to use a recycled container // if possible, otherwise generate a new container. isNewlyRealized = true; CollectionViewGroup group = item as CollectionViewGroup; // DataGrid needs to generate DataGridRows for special items like NewItemPlaceHolder and when adding a new row. // Generate a new container for such cases. bool isNewItemPlaceHolderWhenGrouping = (_factory._generatesGroupItems && group == null); if (_factory._recyclableContainers.Count > 0 && !_factory.Host.IsItemItsOwnContainer(item) && !isNewItemPlaceHolderWhenGrouping) { container = _factory._recyclableContainers.Dequeue(); isNewlyRealized = false; } else { if (group == null || !_factory.IsGrouping) { // generate container for an item container = _factory.Host.GetContainerForItem(item); } else { // generate container for a group container = _factory.ContainerForGroup(group); } } // add the (item, container) to the current block if (container != null) { ItemContainerGenerator.LinkContainerToItem(container, item); _factory.Realize(uBlock, _cachedState.Offset, item, container); // set AlternationIndex on the container (and possibly others) _factory.SetAlternationIndex(_cachedState.Block, _cachedState.Offset, _direction); } } else { // return existing realized container isNewlyRealized = false; RealizedItemBlock rib = (RealizedItemBlock)_cachedState.Block; container = rib.ContainerAt(_cachedState.Offset); } // advance to the next item _cachedState.ItemIndex = itemIndex; if (_direction == GeneratorDirection.Forward) { _cachedState.Block.MoveForward(ref _cachedState, true); } else { _cachedState.Block.MoveBackward(ref _cachedState, true); } } return container; }

從代碼可以看出,一個Generator在GenerateNext時,需要從_factory的ItemsInternal串列讀取一個item,然后再呼叫_factory欄位的Host屬性的GetContainerForItem()方法來為這個item生成一個container,那么這個關鍵的_factory欄位從何而來?事實上,_factory欄位是ItemsContainerGenerator型別,另外ItemsContainerGenerator類內部有一個Generator型別的欄位_generator,這個欄位在創建物件時會將這個ItemsContainerGenerator自身作為引數,傳給其_factory欄位,

Generator.GenerateNext()方法一共被呼叫了兩次,都是在兩個被多載的ItemsContainerGenerator.GenerateNext()方法里:

        DependencyObject IItemContainerGenerator.GenerateNext()
        {
            bool isNewlyRealized;
            if (_generator == null)
                throw new InvalidOperationException(SR.Get(SRID.GenerationNotInProgress));

            return _generator.GenerateNext(true, out isNewlyRealized);
        }

        DependencyObject IItemContainerGenerator.GenerateNext(out bool isNewlyRealized)
        {
            if (_generator == null)
                throw new InvalidOperationException(SR.Get(SRID.GenerationNotInProgress));

            return _generator.GenerateNext(false, out isNewlyRealized);
        }

其中,第一個方法比較重要,它一共被呼叫了三次,其中兩次是在Panel類:一次在Panel.GenerateChildren(),一次在Panel.AddChildren(),二者大同小異,我們只看第一個就足夠了:

        internal virtual void GenerateChildren()
        {
            // This method is typically called during layout, which suspends the dispatcher.
            // Firing an assert causes an exception "Dispatcher processing has been suspended, but messages are still being processed."
            // Besides, the asserted condition can actually arise in practice, and the
            // code responds harmlessly.

            IItemContainerGenerator generator = (IItemContainerGenerator)_itemContainerGenerator;
            if (generator != null)
            {
                using (generator.StartAt(new GeneratorPosition(-1, 0), GeneratorDirection.Forward))
                {
                    UIElement child;
                    while ((child = generator.GenerateNext() as UIElement) != null)
                    {
                        _uiElementCollection.AddInternal(child);
                        generator.PrepareItemContainer(child);
                    }
                }
            }
        }

從代碼可以看到,Panel會回圈呼叫其_itemContainerGenerator欄位(Generator屬性)的GenerateNext()方法直到無法繼續,每次呼叫都會生成一個UIElement型別的child,這個child將被加入Panel的內部UI元素串列,并對其呼叫_itemContainerGenerator.PrepareItemContainer(child)方法,而這里的這個child就是我們前面提到的container,

至此,container和item的來龍去脈我們算基本搞清楚了,

但是,這里的問題是,Panel類的這個神秘的_itemContainerGenerator欄位是從哪里來的?一個Panel怎么會和ItemContainerGenerator扯上關系?秘密就在下面這個方法:

//*************Panel*************

private void ConnectToGenerator() { ItemsControl itemsOwner = ItemsControl.GetItemsOwner(this); if (itemsOwner == null) { // This can happen if IsItemsHost=true, but the panel is not nested in an ItemsControl throw new InvalidOperationException(SR.Get(SRID.Panel_ItemsControlNotFound)); } IItemContainerGenerator itemsOwnerGenerator = itemsOwner.ItemContainerGenerator; if (itemsOwnerGenerator != null) { _itemContainerGenerator = itemsOwnerGenerator.GetItemContainerGeneratorForPanel(this); if (_itemContainerGenerator != null) { _itemContainerGenerator.ItemsChanged += new ItemsChangedEventHandler(OnItemsChanged); ((IItemContainerGenerator)_itemContainerGenerator).RemoveAll(); } } }

 

可以看到,這個方法會先呼叫靜態方法ItemsControl.GetItemsOwner()獲得這個Panel所處的ItemsControl,這個方法的定義如下:

//****************ItemsControl******************* 

/// <summary> /// Returns the ItemsControl for which element is an ItemsHost. /// More precisely, if element is marked by setting IsItemsHost="true" /// in the style for an ItemsControl, or if element is a panel created /// by the ItemsPresenter for an ItemsControl, return that ItemsControl. /// Otherwise, return null. /// </summary> public static ItemsControl GetItemsOwner(DependencyObject element) { ItemsControl container = null; Panel panel = element as Panel; if (panel != null && panel.IsItemsHost) { // see if element was generated for an ItemsPresenter ItemsPresenter ip = ItemsPresenter.FromPanel(panel); if (ip != null) { // if so use the element whose style begat the ItemsPresenter container = ip.Owner; } else { // otherwise use element's templated parent container = panel.TemplatedParent as ItemsControl; } } return container;
}

這個方法的邏輯很簡單:在獲取一個Panel所關聯的ItemsControl時,如果這個Panel的IsItemsHost屬性非真則回傳空值;不然,那么如果這個Panel的TemplateParent是ItemsPresenter,則回傳其Owner,否則則直接回傳這個Panel的TemplateParent,

在知道自己所在的ItemsControl后,這個Panel就能呼叫這個ItemsControl的ItemContainerGenerator屬性的GetItemContainerGeneratorForPanel()方法來獲得一個正確的ItemContainerGenerator給其_itemContainerGenerator欄位(Panel的Generator屬性)賦值,

現在問題的關鍵是,一個Panel的TemplateParent是怎么和一個ItemsControl扯上關系的?我們在第三篇文章介紹ItemsPanelTemplate時曾提到過,ItemsControl的默認Template里的ItemsPresenter只起一個占位符(placeholder)的作用,它的主要角色是接收ItemsControl的ItemsPanel模板,并在ItemsControl應用模板時應用這個模板,

我們再可以看一下ItemsControl的默認ItemsPanel模板:

        <ItemsPanelTemplate x:Key="ItemsPanelTemplate1">
            <StackPanel/>
        </ItemsPanelTemplate>

 (我們前面提到過,ItemsControl類在注冊ItemsPanelTemplateProperty依賴屬性時,其默認值就是StackPanel,另外值得一提的時:ListBoxListView的默認ItemsPanel都是VirtualizingStackPanel,Menu類是WrapPanel,StatusBar類是DockPanel),

而我們知道,要想讓這個ItemsPanel模板起作用,ItemsControl的Template內還必須包含一個ItemsPresenter:

        <Style TargetType="{x:Type ItemsControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ItemsControl}">
                        <Border>
                            <ItemsPresenter />
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

這時一個ItemsControl的Template模板里的ItemsPresenter在應用這個ItemsControl的ItemsPanel模板時,會將模板里面的Panel類控制元件的TemplateParent設定為這個ItemsControl,同時將其IsItemsHost屬性標識為true,

ItemsControl還有一種用法是忽略ItemsPanel,直接在其Template內指定一個"ItemsPanel",如下面的代碼:

        <Style TargetType="{x:Type ItemsControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ItemsControl}">
                        <Border>
                           <StackPanel IsItemsHost="True"/>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

這時ItemsPanel模板的設定將被直接忽略,不過,這時一定要將這個Panel的IsItemsHost設定為True,否則ItemsControl將找不到一個合適的ItemsPanel來顯示串列項,

最后,結合第三篇文章的內容,我們再按照從上至下的順序從整體上梳理一下ItemsControl的模板應用機制:一個ItemsControl在應用模板時,首先會應用Template模板(ControlTemplate型別)生成自身的visual tree(Control類的模板機制),然后Template模板中的ItemsPresenter應用其TemplateParent(即這個ItemsControl)的ItemsPanel模板(ItemsPanelTemplate型別)生成一個visual tree,并把這個visual tree放置在這個ItemsPresenter的位置(ItemsPresenter這時起到占位符的作用),在ItemsPanel模板被應用時,這個面板的TemplateParent會被指向這個ItemsControl,同時其IsItemsHost屬性被標識為true,ItemsControl的ItemContainerGeneror在遍歷自己的ItemsInternal串列并為每個串列項(item)生成一個container,并將ItemsControl的ItemTemplate模板“轉交”(forward)給這個container,這樣這個container就可以應用模板,為與自己對應的資料項(item)生成一個由這個ItemTemplate定義的visual tree,當然具體程序要復雜的多,

 

至此,本文算全部寫完了,最后再強行總結一下WPF的模板機制:

1.FrameworkTemplate是所有模板類的基類,FrameworkElement類有一個FrameworkTemplate型別的TemplateInternal屬性,FrameworkElement.ApplyTemplate()將使用這個屬性的模板物件來生成visual tree,并將這個visual tree賦值給自己的TemplateChild屬性,從而在兩個Visual類物件之間建立起parent-child relationship;

2.FrameworkElement的TemplateInternal屬性是虛屬性,FrameworkElement子類可以通過覆寫這個屬性來自定義模板,只有四個類Control、ContentPresenter、ItemsPresenter、Page覆寫了這個屬性,這意味著只有這4個類及其子類控制元件才能應用自定義的模板,它們也是WPF模板機制的實作基礎;

3.FrameworkTemplate類有三個子類:ControlTemplate、ItemsPanelTemplate和DataTemplate,WPF中這些模板類定義的變數很多,它們的內部實作也不盡相同,不過萬變不離其宗,所有模板類最終都要把自己傳遞到FrameworkElement.TemplateInternal屬性上,才能被應用,生成的visual tree才能被加載到整體的visual tree中,FrameworkElement.ApplyTemplate()方法是FrameworkElement及其子類模板應用的總入口,

  

(WPF源代碼:https://github.com/dotnet/wpf,)

 

(感謝閱讀,歡迎批評指正,轉載請注明出處)

 

 

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

標籤:.NET技术

上一篇:基于.NetCore3.1系列 —— 日志記錄之初識Serilog

下一篇:WCF 動態代理與攔截器

標籤雲
其他(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