public void PistonThread(object state)
        {
            try
            {
                var model = (TypeModel) state;
                Web2PdfTest clone,
                            web2PdfTestEntity = new Web2PdfTest
                            {Prop1 = "1234567", Prop2 = "28383847474", Prop3 = "83837272626"};

                if (Interlocked.Decrement(ref waitingThreads) == 0) gate.Set();
                else gate.WaitOne();

                using (var stream = new MemoryStream())
                {
                    model.Serialize(stream, web2PdfTestEntity);
                    stream.Position = 0;
                    clone = (Web2PdfTest) model.Deserialize(stream, null, typeof (Web2PdfTest));
                }
                if (clone.Prop1 != web2PdfTestEntity.Prop1) throw new DataException("Prop1");
                if (clone.Prop2 != web2PdfTestEntity.Prop2) throw new DataException("Prop2");
                if (clone.Prop3 != web2PdfTestEntity.Prop3) throw new DataException("Prop3");
                Interlocked.Increment(ref success);
            } catch (Exception ex)
            {
                Interlocked.CompareExchange(ref firstException, ex, null);
            }
        }
Example #2
0
        private void PistonThread(object state)
        {
            try
            {
                var         model = (TypeModel)state;
                Web2PdfTest clone,
                            web2PdfTestEntity = new Web2PdfTest
                {
                    Prop1 = "1234567", Prop2 = "28383847474", Prop3 = "83837272626"
                };

                if (Interlocked.Decrement(ref waitingThreads) == 0)
                {
                    gate.Set();
                }
                else
                {
                    gate.WaitOne();
                }

                using (var stream = new MemoryStream())
                {
                    model.Serialize(stream, web2PdfTestEntity);
                    stream.Position = 0;
#pragma warning disable CS0618
                    clone = (Web2PdfTest)model.Deserialize(stream, null, typeof(Web2PdfTest));
#pragma warning restore CS0618
                }
                if (clone.Prop1 != web2PdfTestEntity.Prop1)
                {
                    throw new InvalidDataException("Prop1");
                }
                if (clone.Prop2 != web2PdfTestEntity.Prop2)
                {
                    throw new InvalidDataException("Prop2");
                }
                if (clone.Prop3 != web2PdfTestEntity.Prop3)
                {
                    throw new InvalidDataException("Prop3");
                }
                Interlocked.Increment(ref success);
            } catch (Exception ex)
            {
                Interlocked.CompareExchange(ref firstException, ex, null);
            }
        }