Esempio n. 1
0
		public static void thr1 ()
		{
			int ii;
			NpgsqlTransaction trans = null;
			try {
				NpgsqlConnection conn2 = new NpgsqlConnection (targ_db);
				conn2.Open ();
				asdf a = new asdf ();
				while (true) {
					try {
						while (true) {
							lock (q) {
								if (q.Count > 0) {
									a = q.Dequeue ();
									threads++;
									if (trans == null)
										trans = conn2.BeginTransaction ();
									break;
								}
							}
							if (trans != null) {
								trans.Commit ();
								trans = null;
								lock (q) {
									threads--;
								}
							}
							System.Threading.Thread.Sleep (200);
						}
						try {
							NpgsqlCommand cmd2 = new NpgsqlCommand (a.cmd, conn2);
							for (ii=0; ii<a.data.Length; ii++) {
								object o = a.data [ii];
								if (typeof(bool).IsInstanceOfType (o)) {
									o = (((bool)o == true) ? 1 : 0);
								}
								cmd2.Parameters.Add ("col_" + ii.ToString (), o);
							}
							cmd2.ExecuteNonQuery ();
						} catch (Exception ex1) {
							Console.WriteLine ("exception: " + ex1.Message);
						}
					} finally {
						lock (q) {
							threads--;
						}
					}
				}
				conn2.Close ();
			} catch (Exception ex) {
				Console.WriteLine ("exception: " + ex.Message);
			}
		}
Esempio n. 2
0
        public static void thr1()
        {
            int ii;
            NpgsqlTransaction trans = null;

            try {
                NpgsqlConnection conn2 = new NpgsqlConnection(targ_db);
                conn2.Open();
                asdf a = new asdf();
                while (true)
                {
                    try {
                        while (true)
                        {
                            lock (q) {
                                if (q.Count > 0)
                                {
                                    a = q.Dequeue();
                                    threads++;
                                    if (trans == null)
                                    {
                                        trans = conn2.BeginTransaction();
                                    }
                                    break;
                                }
                            }
                            if (trans != null)
                            {
                                trans.Commit();
                                trans = null;
                                lock (q) {
                                    threads--;
                                }
                            }
                            System.Threading.Thread.Sleep(200);
                        }
                        try {
                            NpgsqlCommand cmd2 = new NpgsqlCommand(a.cmd, conn2);
                            for (ii = 0; ii < a.data.Length; ii++)
                            {
                                object o = a.data [ii];
                                if (typeof(bool).IsInstanceOfType(o))
                                {
                                    o = (((bool)o == true) ? 1 : 0);
                                }
                                cmd2.Parameters.Add("col_" + ii.ToString(), o);
                            }
                            cmd2.ExecuteNonQuery();
                        } catch (Exception ex1) {
                            Console.WriteLine("exception: " + ex1.Message);
                        }
                    } finally {
                        lock (q) {
                            threads--;
                        }
                    }
                }
                conn2.Close();
            } catch (Exception ex) {
                Console.WriteLine("exception: " + ex.Message);
            }
        }