블로그 이미지
SQL Server VS. 석이 minsouk@hotmail.com MSSQL 쿼리성능 관련해 궁금한 사항이 있다면 언제나 누구나 TeamViewer + Line (네이버 japan 메신저) 에 minsouk1 추가 후 연락주세요~ 010-9967-0955 보미아빠

카테고리

보미아빠, 석이 (454)
밥벌이 (16)
싸이클 (1)
일상 (1)
Total226,390
Today19
Yesterday50

달력

« » 2018.12
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

공지사항

Task await

분류없음 / 2018.07.10 15:18

    class Program

    {

        static void Main(string[] args)

        {

            List<Task<string>> lists = new List<Task<string>>();

            Program p = new Program();


            lists.Add(p.Run2());

            lists.Add(p.Run());


            foreach (var a in lists)

                a.Wait();  // 모두 기다리고 출력 


            foreach (var a in lists)

                Console.WriteLine(a.Result);  // 5초 응답 

                    

        }


        async Task<string> Run()

        {

            var a = Task.Delay(1000);

            var b = Task.Delay(1000);

            var c = Task.Delay(1000);

            var d = Task.Delay(1000);

            var e = Task.Delay(1000);


            await a;

            await b;

            await c;

            await d;

            await e;

            Thread.Sleep(3000);   // 전체 처리시간 4초 

            return DateTime.Now.ToString();


        }


        async Task<string> Run2()

        {

            await Task.Delay(1000);

            await Task.Delay(1000);

            await Task.Delay(1000);

            await Task.Delay(1000);

            await Task.Delay(1000);  // 전체 처리시간 5초

            

            return DateTime.Now.ToString();

        }

        

    }

Posted by 보미아빠

c# event

분류없음 / 2018.06.29 15:55

//using System;

//using System.Collections.Generic;

//using System.Linq;

//using System.Text;

//using System.Threading.Tasks;

//using System.Configuration;

//using System.Threading;


//namespace ConsoleApp1

//{

//    public class EvenNumberEventArgs : EventArgs

//    {

//        public EvenNumberEventArgs(int i)

//        {

//            this.I = i;

//        }

//        public int I { get; set; }

//    }


//    class Program

//    {

//        static void Main(string[] args)

//        {

//            new Program().Run();

//        }


//        void Run()

//        {

//            Config config = Config.Instance;

//            EventProcess ep = new EventProcess();

//            //Console.WriteLine(config.SampleApplication);


//            for (int i = 0; i < 10; i++)

//            {

//                config.NumberCheck(i);

//            }

//        }

//    }


//    public sealed class Config

//    {

//        private static readonly Lazy<Config> lazy =

//            new Lazy<Config>(() => new Config(), LazyThreadSafetyMode.ExecutionAndPublication);


//        public static Config Instance { get { return lazy.Value; } }


//        private Config()

//        {

//            //this.SampleApplication = ConfigurationManager.AppSettings["sampleApplication"];

//        }


//        //public string SampleApplication { get; } = string.Empty;


//        public event EventHandler<EvenNumberEventArgs> MyEvent;


//        public void NumberCheck(int i)

//        {

//            if (i % 2 == 0)

//                MyEvent?.Invoke(this, new EvenNumberEventArgs(i));

//        }

//    }


//    class EventProcess

//    {

//        public EventProcess()

//        {

//            Config.Instance.MyEvent += EvenNumber;

//        }

//        void EvenNumber(object o, EvenNumberEventArgs args)

//        {

//            Console.WriteLine(o.GetType());

//            Console.WriteLine(string.Format("this is even Number : {0}", args.I));

//        }

//    }


//}




using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading;

using System.Threading.Tasks;

 

namespace ConsoleApp1

{



    class Program

    {

        static void Main(string[] args)

        {

            new Program().Run();

        }


        void Run()

        {

            Config config = Config.Instance;

            new EventProcess();

            //Console.WriteLine(config.SampleApplication);

            for (int i = 0; i < 10; i++)

            {

                config.NumberCheck(i);

            }

        }

    }


    

    public sealed class Config

    {

        private static readonly Lazy<Config> lazy =

            new Lazy<Config>(() => new Config(), LazyThreadSafetyMode.ExecutionAndPublication);


        public static Config Instance { get { return lazy.Value; } }

        

        private Config()

        {

            //this.SampleApplication = ConfigurationManager.AppSettings["sampleApplication"];

        }


        public Action<object, EvenNumberEventArgs> MyEvent;


        public void NumberCheck(int i)

        {

            if (i % 2 == 0)

                MyEvent?.Invoke(this, new EvenNumberEventArgs(i));

        }


        public class EvenNumberEventArgs : EventArgs

        {

            public EvenNumberEventArgs(int i)

            {

                this.I = i;

            }

            public int I { get; set; }

        }

    }


    class EventProcess

    {

        public EventProcess()

        {

            Config.Instance.MyEvent += EvenNumber;

        }


        void EvenNumber(object o, Config.EvenNumberEventArgs args)

        {

            Console.WriteLine(o.GetType());

            Console.WriteLine(string.Format("this is even Number : {0}", args.I));

        }

    }

}

Posted by 보미아빠

function base n

분류없음 / 2018.05.29 18:07

/****** Object:  UserDefinedFunction [dbo].[F_NUMERIC_TO_BASE_N]    Script Date: 5/29/2018 6:07:05 PM ******/

SET ANSI_NULLS ON

GO


SET QUOTED_IDENTIFIER ON

GO


create function [dbo].[F_NUMERIC_TO_BASE_N]

(

@Number numeric(32,0),

@Base int

)

returns varchar(110)

as


/*

Function: F_NUMERIC_TO_BASE_N


Function F_NUMERIC_TO_BASE_N converts a numeric(32,0) value, @Number,

to a string of digits in number base @Base,

where @Base is between 2 and 36.


Output digits greater than 9 are represented by

uppercase letters A through Z, where A = 10 through Z = 35.

 

If input parameter @Number is negative, the output string

will have a minus sign in the leftmost position.


Any non-null numeric(32,0) value for parameter @Number is valid:

-99999999999999999999999999999999 through

99999999999999999999999999999999.


If input parameters @Number or @Base are null,

or @Base is not between 2 and 36,

then the function returns a null value.

*/


begin


declare @Work_Number numeric(38,0)

declare @Modulus int

declare @Digits varchar(36)

declare @Output_String varchar(110)


if @Number is null or @Base is null or @Base < 2 or @Base > 36 

begin

return null

end


set @Digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

set @Output_String = ''

set @Work_Number = @Number


while 1=1  

begin


Set @Modulus = convert(int,abs(@Work_Number-(round(@Work_Number/@Base,0,1)*@Base)))


set @Output_String = substring(@Digits,@Modulus+1,1) + @Output_String


set @Work_Number = round(@Work_Number/@Base,0,1)


if @Work_Number = 0 break

end -- end while


if @Number < 0 set @Output_String = '-'+@Output_String


return @Output_String


end

GO










declare @times bigint = 1

declare @top_count bigint = 1000


select  dbo.[F_NUMERIC_TO_BASE_N](@times * 100000000 + rn * 1000 , 32)

from 

(

select top (@top_count) row_number() over (order by (select 1)) rn 

from sysobjects a 

cross join sysobjects b 

cross join sysobjects c

) a



Posted by 보미아빠

최근에 달린 댓글

최근에 받은 트랙백

글 보관함