主頁 > .NET開發 > 用了這么多年的泛型,你對它到底有多了解?

用了這么多年的泛型,你對它到底有多了解?

2020-09-15 18:21:29 .NET開發

現代程式員寫代碼沒有人敢說自己沒用過泛型,這個泛型模板T可以被任何你想要的型別替代,確實很魔法很神奇,很多人也習以為常了,但就是這么有趣的泛型T底層到底是怎么幫你實作的,不知道有多少人清楚底層玩法,這篇我就試著來分享一下,不一定全對哈,,,

一:沒有泛型前

現在的netcore 3.1和最新的.netframework8早已經沒有當初那個被人詬病的ArrayList了,但很巧這玩意不得不說,因為它決定了C#團隊痛改前非,拋棄過往重新上路,上一段ArrayList案例代碼,

    public class ArrayList
    {
        private object[] items;

        private int index = 0;

        public ArrayList()
        {
            items = new object[10];
        }

        public void Add(object item)
        {
            items[index++] = item;
        }
    }

上面這段代碼,為了保證在Add中可以塞入各種型別 eg: int,double,class, 就想到了一個絕招用祖宗類object接收,這就引入了兩大問題,裝箱拆箱和型別安全,

1. 裝箱拆箱

這個很好理解,因為你使用了祖宗類,所以當你 Add 的時候塞入的是值型別的話,自然就有裝箱操作,比如下面代碼:

            ArrayList arrayList = new ArrayList();
            arrayList.Add(3);

<1> 占用更大的空間

這個問題我準備用windbg看一下,相信大家知道一個int型別占用4個位元組,那裝箱到堆上是幾個位元組呢,好奇吧??,

原始代碼和IL代碼如下:

        public static void Main(string[] args)
        {
            var num = 10;
            var obj = (object)num;
            Console.Read();
        }

    IL_0000: nop
	IL_0001: ldc.i4.s 10
	IL_0003: stloc.0
	IL_0004: ldloc.0
	IL_0005: box [mscorlib]System.Int32
	IL_000a: stloc.1
	IL_000b: call int32 [mscorlib]System.Console::Read()
	IL_0010: pop
	IL_0011: ret

可以清楚的看到IL_0005 中有一個box指令,裝箱沒有問題,然后抓一下dump檔案,

~0s -> !clrstack -l -> !do 0x0000018300002d48


0:000> ~0s
ntdll!ZwReadFile+0x14:
00007ff9`fc7baa64 c3              ret
0:000> !clrstack -l
OS Thread Id: 0xfc (0)
        Child SP               IP Call Site
0000002c397fedf0 00007ff985c808f3 ConsoleApp2.Program.Main(System.String[]) [C:\dream\Csharp\ConsoleApp1\ConsoleApp2\Program.cs @ 28]
    LOCALS:
        0x0000002c397fee2c = 0x000000000000000a
        0x0000002c397fee20 = 0x0000018300002d48

0000002c397ff038 00007ff9e51b6c93 [GCFrame: 0000002c397ff038] 
0:000> !do 0x0000018300002d48
Name:        System.Int32
MethodTable: 00007ff9e33285a0
EEClass:     00007ff9e34958a8
Size:        24(0x18) bytes
File:        C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
Fields:
              MT    Field   Offset                 Type VT     Attr            Value Name
00007ff9e33285a0  40005a0        8         System.Int32  1 instance               10 m_value

倒數第5行 Size: 24(0x18) bytes, 可以清楚的看到是24位元組, 為什么是24個位元組,8(同步塊指標) + 8(方法表指標) + 4(物件大小)=20,但因為是x64位,記憶體是按8對齊,也就是要按8的倍數計算,所以占用是 8+8+8 =24 位元組,原來只有4位元組的大小因為裝箱已被爆到24位元組,如果是10000個值型別的裝箱那空間占用是不是挺可怕的?

<2> 堆疊到堆的裝箱搬運到運輸到售后到無害化處理都需要付出重大的人力和機器成本

2. 型別不安全

很簡單,因為是祖宗型別object,所以無法避免程式員使用亂七八糟的型別,當然這可能是無意的,但是編譯器確無法規避,代碼如下:


            ArrayList arrayList = new ArrayList();
            arrayList.Add(3);
            arrayList.Add(new Action<int>((num) => { }));
            arrayList.Add(new object());

面對這兩大尷尬的問題,C#團隊決定重新設計一個型別,實作一定終身,這就有了泛型,

二:泛型的出現

1. 救世主

首先可以明確的說,泛型就是為了解決這兩個問題而生的,你可以在底層提供的List<T>中使用List<int>,List<double>,,,等等你看得上的型別,而這種技術的底層實作原理才是本篇關注的重點,


        public static void Main(string[] args)
        {
            List<double> list1 = new List<double>();
            List<string> list3 = new List<string>();
            ...
        }

三:泛型原理探究

這個問題的探索其實就是 List<T> -> List<int>在何處實作了 T -> int 的替換,反觀java,它的泛型實作其實在底層還是用object來替換的,C#肯定不是這么做的,不然也沒這篇文章啦,要知道在哪個階段被替換了,你起碼要知道C#代碼編譯的幾個階段,為了理解方便,我畫一張圖吧,

流程大家也看到了,要么在MSIL中被替換,要么在JIT編譯中被替換,,,


        public static void Main(string[] args)
        {
            List<double> list1 = new List<double>();
            List<int> list2 = new List<int>();
            List<string> list3 = new List<string>();
            List<int[]> list4 = new List<int[]>();

            Console.ReadLine();
        }

1. 在第一階段探究

因為第一階段是MSIL代碼,所以用ILSpy看一下中間代碼即可,

		IL_0000: nop
		IL_0001: newobj instance void class [mscorlib]System.Collections.Generic.List`1<float64>::.ctor()
		IL_0006: stloc.0
		IL_0007: newobj instance void class [mscorlib]System.Collections.Generic.List`1<int32>::.ctor()
		IL_000c: stloc.1
		IL_000d: newobj instance void class [mscorlib]System.Collections.Generic.List`1<string>::.ctor()
		IL_0012: stloc.2
		IL_0013: newobj instance void class [mscorlib]System.Collections.Generic.List`1<int32[]>::.ctor()
		IL_0018: stloc.3
		IL_0019: call string [mscorlib]System.Console::ReadLine()
		IL_001e: pop
		IL_001f: ret

.class public auto ansi serializable beforefieldinit System.Collections.Generic.List`1<T>
	extends System.Object
	implements class System.Collections.Generic.IList`1<!T>,
	           class System.Collections.Generic.ICollection`1<!T>,
	           class System.Collections.Generic.IEnumerable`1<!T>,
	           System.Collections.IEnumerable,
	           System.Collections.IList,
	           System.Collections.ICollection,
	           class System.Collections.Generic.IReadOnlyList`1<!T>,
	           class System.Collections.Generic.IReadOnlyCollection`1<!T>

從上面的IL代碼中可以看到,最終的類定義還是 System.Collections.Generic.List1\<T>,說明在中間代碼階段還是沒有實作 T -> int 的替換,

2. 在第二階段探究

想看到JIT編譯后的代碼,這個說難也不難,其實每個物件頭上都有一個方法表指標,而這個指標指向的就是方法表,方法表中有該型別的所有最終生成方法,如果不好理解,我就畫個圖,

!dumpheap -stat 尋找托管堆上的四個List物件,


0:000> !dumpheap -stat
Statistics:
              MT    Count    TotalSize Class Name
00007ff9e3314320        1           32 Microsoft.Win32.SafeHandles.SafeViewOfFileHandle
00007ff9e339b4b8        1           40 System.Collections.Generic.List`1[[System.Double, mscorlib]]
00007ff9e333a068        1           40 System.Collections.Generic.List`1[[System.Int32, mscorlib]]
00007ff9e3330d58        1           40 System.Collections.Generic.List`1[[System.String, mscorlib]]
00007ff9e3314a58        1           40 System.IO.Stream+NullStream
00007ff9e3314510        1           40 Microsoft.Win32.Win32Native+InputRecord
00007ff9e3314218        1           40 System.Text.InternalEncoderBestFitFallback
00007ff985b442c0        1           40 System.Collections.Generic.List`1[[System.Int32[], mscorlib]]
00007ff9e338fd28        1           48 System.Text.DBCSCodePageEncoding+DBCSDecoder
00007ff9e3325ef0        1           48 System.SharedStatics

可以看到從托管堆中找到了4個list物件,現在我就挑一個最簡單的 System.Collections.Generic.List1[[System.Int32, mscorlib]] ,前面的 00007ff9e333a068 就是方法表地址,

!dumpmt -md 00007ff9e333a068


0:000> !dumpmt -md 00007ff9e333a068
EEClass:         00007ff9e349b008
Module:          00007ff9e3301000
Name:            System.Collections.Generic.List`1[[System.Int32, mscorlib]]
mdToken:         00000000020004af
File:            C:\WINDOWS\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll
BaseSize:        0x28
ComponentSize:   0x0
Slots in VTable: 77
Number of IFaces in IFaceMap: 8
--------------------------------------
MethodDesc Table
           Entry       MethodDesc    JIT Name
00007ff9e3882450 00007ff9e3308de8 PreJIT System.Object.ToString()
00007ff9e389cc60 00007ff9e34cb9b0 PreJIT System.Object.Equals(System.Object)
00007ff9e3882090 00007ff9e34cb9d8 PreJIT System.Object.GetHashCode()
00007ff9e387f420 00007ff9e34cb9e0 PreJIT System.Object.Finalize()
00007ff9e38a3650 00007ff9e34dc6e8 PreJIT System.Collections.Generic.List`1[[System.Int32, mscorlib]].Add(Int32)
00007ff9e4202dc0 00007ff9e34dc7f8 PreJIT System.Collections.Generic.List`1[[System.Int32, mscorlib]].Insert(Int32, Int32)

上面方法表中的方法過多,我做了一下刪減,可以清楚的看到,此時Add方法已經接受(Int32)型別的資料了,說明在JIT編譯之后,終于實作了 T -> int 的替換,然后再把 List<double> 打出來看一下,


0:000> !dumpmt -md 00007ff9e339b4b8
MethodDesc Table
           Entry       MethodDesc    JIT Name
00007ff9e3882450 00007ff9e3308de8 PreJIT System.Object.ToString()
00007ff9e389cc60 00007ff9e34cb9b0 PreJIT System.Object.Equals(System.Object)
00007ff9e3882090 00007ff9e34cb9d8 PreJIT System.Object.GetHashCode()
00007ff9e387f420 00007ff9e34cb9e0 PreJIT System.Object.Finalize()
00007ff9e4428730 00007ff9e34e4170 PreJIT System.Collections.Generic.List`1[[System.Double, mscorlib]].Add(Double)
00007ff9e3867a00 00007ff9e34e4280 PreJIT System.Collections.Generic.List`1[[System.Double, mscorlib]].Insert(Int32, Double)

上面看的都是值型別,接下來再看一下如果 T 是參考型別會是怎么樣呢?


0:000> !dumpmt -md 00007ff9e3330d58
MethodDesc Table
           Entry       MethodDesc    JIT Name
00007ff9e3890060 00007ff9e34eb058 PreJIT System.Collections.Generic.List`1[[System.__Canon, mscorlib]].Add(System.__Canon)

0:000> !dumpmt -md 00007ff985b442c0
MethodDesc Table
           Entry       MethodDesc    JIT Name
00007ff9e3890060 00007ff9e34eb058 PreJIT System.Collections.Generic.List`1[[System.__Canon, mscorlib]].Add(System.__Canon)

可以看到當是List<int[]>List<string> 的時候,JIT使用了 System.__Canon 這么一個型別作為替代,有可能人家是攝影愛好者吧,為什么用__Canon替代參考型別,這是因為它想讓能共享代碼區域的方法都共享來節省空間和記憶體吧,不信的話可以看看它們的Entry列都是同一個記憶體地址:00007ff9e3890060, 列印出來就是這么一段匯編,


0:000> !u 00007ff9e3890060
preJIT generated code
System.Collections.Generic.List`1[[System.__Canon, mscorlib]].Add(System.__Canon)
Begin 00007ff9e3890060, size 4a
>>> 00007ff9`e3890060 57              push    rdi
00007ff9`e3890061 56              push    rsi
00007ff9`e3890062 4883ec28        sub     rsp,28h
00007ff9`e3890066 488bf1          mov     rsi,rcx
00007ff9`e3890069 488bfa          mov     rdi,rdx
00007ff9`e389006c 8b4e18          mov     ecx,dword ptr [rsi+18h]
00007ff9`e389006f 488b5608        mov     rdx,qword ptr [rsi+8]
00007ff9`e3890073 3b4a08          cmp     ecx,dword ptr [rdx+8]
00007ff9`e3890076 7422            je      mscorlib_ni+0x59009a (00007ff9`e389009a)
00007ff9`e3890078 488b4e08        mov     rcx,qword ptr [rsi+8]
00007ff9`e389007c 8b5618          mov     edx,dword ptr [rsi+18h]
00007ff9`e389007f 448d4201        lea     r8d,[rdx+1]
00007ff9`e3890083 44894618        mov     dword ptr [rsi+18h],r8d
00007ff9`e3890087 4c8bc7          mov     r8,rdi
00007ff9`e389008a ff152088faff    call    qword ptr [mscorlib_ni+0x5388b0 (00007ff9`e38388b0)] (JitHelp: CORINFO_HELP_ARRADDR_ST)
00007ff9`e3890090 ff461c          inc     dword ptr [rsi+1Ch]
00007ff9`e3890093 4883c428        add     rsp,28h
00007ff9`e3890097 5e              pop     rsi
00007ff9`e3890098 5f              pop     rdi
00007ff9`e3890099 c3              ret
00007ff9`e389009a 8b5618          mov     edx,dword ptr [rsi+18h]
00007ff9`e389009d ffc2            inc     edx
00007ff9`e389009f 488bce          mov     rcx,rsi
00007ff9`e38900a2 90              nop
00007ff9`e38900a3 e8c877feff      call    mscorlib_ni+0x577870 (00007ff9`e3877870) (System.Collections.Generic.List`1[[System.__Canon, mscorlib]].EnsureCapacity(Int32), mdToken: 00000000060039e5)
00007ff9`e38900a8 ebce            jmp     mscorlib_ni+0x590078 (00007ff9`e3890078)

然后再回過頭看List<int>List<double> ,從Entry列中看確實不是一個地址,說明List<int>List<double> 是兩個完全不一樣的Add方法,看得懂匯編的可以自己看一下哈,,,

MethodDesc Table
           Entry       MethodDesc    JIT Name
00007ff9e38a3650 00007ff9e34dc6e8 PreJIT System.Collections.Generic.List`1[[System.Int32, mscorlib]].Add(Int32)
00007ff9e4428730 00007ff9e34e4170 PreJIT System.Collections.Generic.List`1[[System.Double, mscorlib]].Add(Double)

0:000> !u 00007ff9e38a3650
preJIT generated code
System.Collections.Generic.List`1[[System.Int32, mscorlib]].Add(Int32)
Begin 00007ff9e38a3650, size 50
>>> 00007ff9`e38a3650 57              push    rdi
00007ff9`e38a3651 56              push    rsi
00007ff9`e38a3652 4883ec28        sub     rsp,28h
00007ff9`e38a3656 488bf1          mov     rsi,rcx
00007ff9`e38a3659 8bfa            mov     edi,edx
00007ff9`e38a365b 8b5618          mov     edx,dword ptr [rsi+18h]
00007ff9`e38a365e 488b4e08        mov     rcx,qword ptr [rsi+8]
00007ff9`e38a3662 3b5108          cmp     edx,dword ptr [rcx+8]
00007ff9`e38a3665 7423            je      mscorlib_ni+0x5a368a (00007ff9`e38a368a)
00007ff9`e38a3667 488b5608        mov     rdx,qword ptr [rsi+8]
00007ff9`e38a366b 8b4e18          mov     ecx,dword ptr [rsi+18h]
00007ff9`e38a366e 8d4101          lea     eax,[rcx+1]
00007ff9`e38a3671 894618          mov     dword ptr [rsi+18h],eax
00007ff9`e38a3674 3b4a08          cmp     ecx,dword ptr [rdx+8]
00007ff9`e38a3677 7321            jae     mscorlib_ni+0x5a369a (00007ff9`e38a369a)
00007ff9`e38a3679 4863c9          movsxd  rcx,ecx
00007ff9`e38a367c 897c8a10        mov     dword ptr [rdx+rcx*4+10h],edi
00007ff9`e38a3680 ff461c          inc     dword ptr [rsi+1Ch]
00007ff9`e38a3683 4883c428        add     rsp,28h
00007ff9`e38a3687 5e              pop     rsi
00007ff9`e38a3688 5f              pop     rdi
00007ff9`e38a3689 c3              ret
00007ff9`e38a368a 8b5618          mov     edx,dword ptr [rsi+18h]
00007ff9`e38a368d ffc2            inc     edx
00007ff9`e38a368f 488bce          mov     rcx,rsi
00007ff9`e38a3692 90              nop
00007ff9`e38a3693 e8a8e60700      call    mscorlib_ni+0x621d40 (00007ff9`e3921d40) (System.Collections.Generic.List`1[[System.Int32, mscorlib]].EnsureCapacity(Int32), mdToken: 00000000060039e5)
00007ff9`e38a3698 ebcd            jmp     mscorlib_ni+0x5a3667 (00007ff9`e38a3667)
00007ff9`e38a369a e8bf60f9ff      call    mscorlib_ni+0x53975e (00007ff9`e383975e) (mscorlib_ni)
00007ff9`e38a369f cc              int     3


0:000> !u 00007ff9e4428730
preJIT generated code
System.Collections.Generic.List`1[[System.Double, mscorlib]].Add(Double)
Begin 00007ff9e4428730, size 5a
>>> 00007ff9`e4428730 56              push    rsi
00007ff9`e4428731 4883ec20        sub     rsp,20h
00007ff9`e4428735 488bf1          mov     rsi,rcx
00007ff9`e4428738 8b5618          mov     edx,dword ptr [rsi+18h]
00007ff9`e442873b 488b4e08        mov     rcx,qword ptr [rsi+8]
00007ff9`e442873f 3b5108          cmp     edx,dword ptr [rcx+8]
00007ff9`e4428742 7424            je      mscorlib_ni+0x1128768 (00007ff9`e4428768)
00007ff9`e4428744 488b5608        mov     rdx,qword ptr [rsi+8]
00007ff9`e4428748 8b4e18          mov     ecx,dword ptr [rsi+18h]
00007ff9`e442874b 8d4101          lea     eax,[rcx+1]
00007ff9`e442874e 894618          mov     dword ptr [rsi+18h],eax
00007ff9`e4428751 3b4a08          cmp     ecx,dword ptr [rdx+8]
00007ff9`e4428754 732e            jae     mscorlib_ni+0x1128784 (00007ff9`e4428784)
00007ff9`e4428756 4863c9          movsxd  rcx,ecx
00007ff9`e4428759 f20f114cca10    movsd   mmword ptr [rdx+rcx*8+10h],xmm1
00007ff9`e442875f ff461c          inc     dword ptr [rsi+1Ch]
00007ff9`e4428762 4883c420        add     rsp,20h
00007ff9`e4428766 5e              pop     rsi
00007ff9`e4428767 c3              ret
00007ff9`e4428768 f20f114c2438    movsd   mmword ptr [rsp+38h],xmm1
00007ff9`e442876e 8b5618          mov     edx,dword ptr [rsi+18h]
00007ff9`e4428771 ffc2            inc     edx
00007ff9`e4428773 488bce          mov     rcx,rsi
00007ff9`e4428776 90              nop
00007ff9`e4428777 e854fbffff      call    mscorlib_ni+0x11282d0 (00007ff9`e44282d0) (System.Collections.Generic.List`1[[System.Double, mscorlib]].EnsureCapacity(Int32), mdToken: 00000000060039e5)
00007ff9`e442877c f20f104c2438    movsd   xmm1,mmword ptr [rsp+38h]
00007ff9`e4428782 ebc0            jmp     mscorlib_ni+0x1128744 (00007ff9`e4428744)
00007ff9`e4428784 e8d50f41ff      call    mscorlib_ni+0x53975e (00007ff9`e383975e) (mscorlib_ni)
00007ff9`e4428789 cc              int     3

可能你有點蒙,我畫一張圖吧,

四: 總結

泛型T真正的被代替是在 JIT編譯時才實作的,四個List<T> 會生成四個具有相應具體型別的類物件,所以就不存在拆箱和裝箱的問題,而型別的限定visualstudio編譯器工具提前就幫我們約束好啦,

夜深了,先休息啦! 希望本篇對你有幫助,


如您有更多問題與我互動,掃描下方進來吧~


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

標籤:C#

上一篇:C# Session 只有在組態檔或 Page 指令中將 enableSessionState 設定為 true 時,才能使用會話狀態。

下一篇:C# 結構體

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